Skip to content

Commit a839583

Browse files
committed
Eagerly clear buffer when past a certain size
1 parent 336ce1c commit a839583

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/redis_client/ruby_connection/buffered_io.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ def fill_buffer(strict, size = @chunk_size)
194194
start = @offset - buffer_size
195195
empty_buffer = start >= 0
196196

197+
if !empty_buffer && @offset > (@chunk_size * 2)
198+
old_buffer = @buffer
199+
@buffer = @buffer.byteslice(@offset..-1)
200+
old_buffer.clear
201+
@offset = 0
202+
start = @offset - @buffer.bytesize
203+
end
204+
197205
loop do
198206
bytes = if empty_buffer
199207
@io.read_nonblock([remaining, @chunk_size].max, @buffer, exception: false)

0 commit comments

Comments
 (0)