mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a55abcc0ca
commit
6776e0bc99
1 changed files with 5 additions and 2 deletions
7
io.c
7
io.c
|
@ -11163,8 +11163,10 @@ copy_stream_fallback_body(VALUE arg)
|
|||
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)
|
|||
}
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue