diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-14 15:58:11 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-09-14 23:21:44 +0900 |
| commit | 6f1c08f7d8a43a5d220aca7a5c449a8d04d3017b (patch) | |
| tree | 909b7875490061854828f40e5495e8cc335c631d /mrbgems/mruby-io/mrblib/io.rb | |
| parent | dcc2d44d930ee5dea7e737ad6fa298d3f4bf9f59 (diff) | |
| download | mruby-6f1c08f7d8a43a5d220aca7a5c449a8d04d3017b.tar.gz mruby-6f1c08f7d8a43a5d220aca7a5c449a8d04d3017b.zip | |
Replace `String#byteslice` by custom `IO._bufread`.
`byteslice` creates 2 string objects. `_bufread` creates one, and
modifies the original buffer string, that is more efficient.
Diffstat (limited to 'mrbgems/mruby-io/mrblib/io.rb')
| -rw-r--r-- | mrbgems/mruby-io/mrblib/io.rb | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb index a6e3ef3de..aaf22da2e 100644 --- a/mrbgems/mruby-io/mrblib/io.rb +++ b/mrbgems/mruby-io/mrblib/io.rb @@ -208,8 +208,7 @@ class IO if length consume = (length <= @buf.bytesize) ? length : @buf.bytesize - array.push @buf.byteslice(0, consume) - @buf = @buf.byteslice(consume, @buf.bytesize - consume) + array.push IO._bufread(@buf, consume) length -= consume break if length == 0 else @@ -255,13 +254,11 @@ class IO end if limit && limit <= @buf.bytesize - array.push @buf.byteslice(0, limit) - @buf = @buf.byteslice(limit, @buf.bytesize - limit) + array.push IO._bufread(@buf, limit) break elsif idx = @buf.index(rs) len = idx + rs.bytesize - array.push @buf.byteslice(0, len) - @buf = @buf.byteslice(len, @buf.bytesize - len) + array.push IO._bufread(@buf, len) break else array.push @buf @@ -284,9 +281,7 @@ class IO def readchar _read_buf - c = @buf.byteslice(0,1) - @buf = @buf.byteslice(1, @buf.bytesize) - c + IO._bufread(@buf, 1) end def getc |
