diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-12-27 04:23:34 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-12-27 04:23:34 +0000 |
commit | 2873361069dc2f8c793875316a0a2c9b8fa54761 (patch) | |
tree | c5ac54a752b01c92379460ac2ea912f0562b75b3 | |
parent | 40c22b3f0a2ace6e4b51a39624ac5ed5ee3d0162 (diff) | |
download | rainbows-2873361069dc2f8c793875316a0a2c9b8fa54761.tar.gz |
It's slightly faster this way, but string slicing sucks anyways :<
-rw-r--r-- | lib/rainbows/fiber/io.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb index 94996ee..6c3d91c 100644 --- a/lib/rainbows/fiber/io.rb +++ b/lib/rainbows/fiber/io.rb @@ -59,19 +59,17 @@ class Rainbows::Fiber::IO else begin (rv = @to_io.write_nonblock(buf)) == buf.bytesize and return - buf = byte_slice(buf, rv..-1) + buf = byte_slice(buf, rv) rescue Errno::EAGAIN kgio_wait_writable end while true end end - def byte_slice(buf, range) # :nodoc: - if buf.encoding != Encoding::BINARY - buf.dup.force_encoding(Encoding::BINARY)[range] - else - buf[range] - end + def byte_slice(buf, start) # :nodoc: + buf.encoding == Encoding::BINARY or + buf = buf.dup.force_encoding(Encoding::BINARY) + buf.slice(start, buf.size) end # used for reading headers (respecting keepalive_timeout) |