[#62297] Re: [ruby-cvs:52906] nari:r45760 (trunk): * gc.c (gc_after_sweep): suppress unnecessary expanding heap. — Eric Wong <normalperson@...>
nari@ruby-lang.org wrote:
7 messages
2014/05/02
[#62307] Re: [ruby-cvs:52906] nari:r45760 (trunk): * gc.c (gc_after_sweep): suppress unnecessary expanding heap.
— SASADA Koichi <ko1@...>
2014/05/03
(2014/05/03 4:41), Eric Wong wrote:
[#62402] Re: [ruby-cvs:52906] nari:r45760 (trunk): * gc.c (gc_after_sweep): suppress unnecessary expanding heap.
— Eric Wong <normalperson@...>
2014/05/05
SASADA Koichi <ko1@atdot.net> wrote:
[#62523] [ruby-trunk - Feature #9632] [PATCH 0/2] speedup IO#close with linked-list from ccan — ko1@...
Issue #9632 has been updated by Koichi Sasada.
3 messages
2014/05/11
[#62556] doxygen (Re: Re: [ruby-trunk - Feature #9632] [PATCH 0/2] speedup IO#close with linked-list from ccan) — Tanaka Akira <akr@...>
2014-05-11 8:50 GMT+09:00 Eric Wong <normalperson@yhbt.net>:
3 messages
2014/05/13
[#62727] [RFC] vm_method.c (rb_method_entry_make): avoid freed me in m_tbl — Eric Wong <normalperson@...>
rb_unlink_method_entry may cause old_me to be swept before the new
7 messages
2014/05/24
[#63039] Re: [RFC] vm_method.c (rb_method_entry_make): avoid freed me in m_tbl
— SASADA Koichi <ko1@...>
2014/06/10
Hi,
[#63077] Re: [RFC] vm_method.c (rb_method_entry_make): avoid freed me in m_tbl
— Eric Wong <normalperson@...>
2014/06/10
SASADA Koichi <ko1@atdot.net> wrote:
[#63086] Re: [RFC] vm_method.c (rb_method_entry_make): avoid freed me in m_tbl
— SASADA Koichi <ko1@...>
2014/06/11
(2014/06/11 4:47), Eric Wong wrote:
[#63087] Re: [RFC] vm_method.c (rb_method_entry_make): avoid freed me in m_tbl
— Eric Wong <normalperson@...>
2014/06/11
SASADA Koichi <ko1@atdot.net> wrote:
[#62862] [RFC] README.EXT: document rb_gc_register_mark_object — Eric Wong <normalperson@...>
Any comment on officially supporting this as part of the C API?
5 messages
2014/05/30
[ruby-core:62439] [ruby-trunk - Feature #9807] String.new with block
From:
duerst@...
Date:
2014-05-07 05:54:29 UTC
List:
ruby-core #62439
Issue #9807 has been updated by Martin D端rst.
Michael Kohl wrote:
> After a discussion in our team chat today, I wondered if it would be a good idea to have a version of String.new that accepts a block and works as a string builder. Something like
>
> string = String.new("foo") do |s|
> s << "bar"
> end
> string #=> "foobar"
>
> If the argument is omitted an empty string would be passed to the block instead.
Like Matthew, I'd also like to see some examples, in particular one that shows how this is different from String.new("foobar") (or even better, from "foobar").
> That could be a nice solution to avoid all the Array#join and "".tap hacks for string creation.
I think "empty string would be passed to the block" may be quite misleading, because that way, people understand the block variable as a string, which would mean that with multiple <<, it's very inefficient.
I think using a different block variable could make things clearer. And showing a simple implementation may make things ever clearer:
class String
def initialize(...)
# current stuff omitted
if block_given?
builder = []
yield builder
replace builder.join
end
end
end
That would put the "hack" to collect a large number of Strings in an array to avoid O(n**2) performance penalty of repeated string concatenation "under the hood". The problem I see is that making the builder array available inside a block limits its usability. That's where examples would help.
I was just looking at examples of where I use the above "hack", and one I found, which might be fairly typical, is something like:
result = []
foos.each do |foo|
result << foo.process
end
result.join
That would now become something like
String.new do |buffer|
foos.each do |foo|
buffer << foo.process
end
end
Is that what you have in mind?
----------------------------------------
Feature #9807: String.new with block
https://bugs.ruby-lang.org/issues/9807#change-46586
* Author: Michael Kohl
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
----------------------------------------
After a discussion in our team chat today, I wondered if it would be a good idea to have a version of String.new that accepts a block and works as a string builder. Something like
string = String.new("foo") do |s|
s << "bar"
end
string #=> "foobar"
If the argument is omitted an empty string would be passed to the block instead.
That could be a nice solution to avoid all the Array#join and "".tap hacks for string creation.
--
https://bugs.ruby-lang.org/