Skip to content

Undo BufferedIO#rbuf_consume_all_shareable! optimization #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions lib/net/protocol.rb
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ def read(len, dest = ''.b, ignore_eof = false)
read_bytes = 0
begin
while read_bytes + rbuf_size < len
if s = rbuf_consume_all_shareable!
if s = rbuf_consume_all
read_bytes += s.bytesize
dest << s
end
@@ -178,7 +178,7 @@ def read_all(dest = ''.b)
read_bytes = 0
begin
while true
if s = rbuf_consume_all_shareable!
if s = rbuf_consume_all
read_bytes += s.bytesize
dest << s
end
@@ -250,18 +250,8 @@ def rbuf_size
@rbuf.bytesize - @rbuf_offset
end

# Warning: this method may share the buffer to avoid
# copying. The caller must no longer use the returned
# string once rbuf_fill has been called again
def rbuf_consume_all_shareable!
@rbuf_empty = true
buf = if @rbuf_offset == 0
@rbuf
else
@rbuf.byteslice(@rbuf_offset..-1)
end
@rbuf_offset = @rbuf.bytesize
buf
def rbuf_consume_all
rbuf_consume if rbuf_size > 0
end

def rbuf_consume(len = nil)