ruby-changes:49517
From: normal <ko1@a...>
Date: Sat, 6 Jan 2018 06:14:23 +0900 (JST)
Subject: [ruby-changes:49517] normal:r61632 (trunk): io.c: clear Strings we create for IO.copy_stream
normal 2018-01-06 06:14:19 +0900 (Sat, 06 Jan 2018) New Revision: 61632 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61632 Log: io.c: clear Strings we create for IO.copy_stream While we can't recycle strings after giving them rb_funcall*, we can reduce their malloc overhead by resizing them to zero. This only affects cases where either `src' or `dst' is a non-IO object and either `copy_length' is passed or there is pre-existing data in the read buffer. * io.c (copy_stream_fallback_body): clear when done with `copy_length' (copy_stream_body): clear when done with pre-existing read buffer Modified files: trunk/io.c Index: io.c =================================================================== --- io.c (revision 61631) +++ io.c (revision 61632) @@ -11163,8 +11163,10 @@ copy_stream_fallback_body(VALUE arg) https://github.com/ruby/ruby/blob/trunk/io.c#L11163 l = buflen; } else { - if (rest == 0) - break; + if (rest == 0) { + rb_str_resize(buf, 0); + break; + } l = buflen < rest ? buflen : (long)rest; } if (stp->src_fd == -1) { @@ -11305,6 +11307,7 @@ copy_stream_body(VALUE arg) https://github.com/ruby/ruby/blob/trunk/io.c#L11307 } else /* others such as StringIO */ rb_io_write(dst_io, str); + rb_str_resize(str, 0); stp->total += len; if (stp->copy_length != (off_t)-1) stp->copy_length -= len; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/