From dbd7eef39fc69c92b0df8208946ce90cbc258309 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Tue, 14 Jan 2025 15:49:57 +0900 Subject: [PATCH] Use slice --- lib/fluent/compat/socket_util.rb | 2 +- lib/fluent/plugin/in_syslog.rb | 2 +- lib/fluent/plugin/in_tail.rb | 2 +- lib/fluent/plugin/in_tcp.rb | 4 ++-- lib/fluent/plugin_helper/server.rb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/fluent/compat/socket_util.rb b/lib/fluent/compat/socket_util.rb index 8a9d8fd20b..18f0d25035 100644 --- a/lib/fluent/compat/socket_util.rb +++ b/lib/fluent/compat/socket_util.rb @@ -82,7 +82,7 @@ def on_read(data) @callback.call(msg, @addr) pos = i + @delimiter.length end - @buffer.slice!(0, pos) if pos > 0 + @buffer = @buffer.slice(pos..) if pos > 0 rescue => e @log.error "unexpected error", error: e close diff --git a/lib/fluent/plugin/in_syslog.rb b/lib/fluent/plugin/in_syslog.rb index 3d4b205c98..bdc11858a7 100644 --- a/lib/fluent/plugin/in_syslog.rb +++ b/lib/fluent/plugin/in_syslog.rb @@ -212,7 +212,7 @@ def start_tcp_server(tls: false) message_handler(msg, conn) end end - buffer.slice!(0, pos) if pos > 0 + buffer.slice(pos..) if pos > 0 end end end diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 23a2af7c4b..91395a8e1a 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -1058,7 +1058,7 @@ def read_lines(lines) @buffer.freeze slice_position = idx + 1 rbuf = @buffer.slice(0, slice_position) - @buffer = @buffer.slice(slice_position, @buffer.size - slice_position) + @buffer = @buffer.slice(slice_position..) idx = @buffer.index(@eol) is_long_line = @max_line_size && ( diff --git a/lib/fluent/plugin/in_tcp.rb b/lib/fluent/plugin/in_tcp.rb index 9ecb6b793d..b31f1e6ebc 100644 --- a/lib/fluent/plugin/in_tcp.rb +++ b/lib/fluent/plugin/in_tcp.rb @@ -149,7 +149,7 @@ def start router.emit(tag, time, record) end end - buf.slice!(0, pos) if pos > 0 + buf = buf.slice(pos..) if pos > 0 # If the buffer size exceeds the limit here, it means that the next message will definitely exceed the limit. # So we should clear the buffer here. Otherwise, it will keep storing useless data until the next delimiter comes. if !@message_length_limit.nil? && @message_length_limit < buf.bytesize @@ -198,7 +198,7 @@ def start end end router.emit_stream(@tag, es) - buf.slice!(0, pos) if pos > 0 + buf = buf.slice(pos..) if pos > 0 # If the buffer size exceeds the limit here, it means that the next message will definitely exceed the limit. # So we should clear the buffer here. Otherwise, it will keep storing useless data until the next delimiter comes. if !@message_length_limit.nil? && @message_length_limit < buf.bytesize diff --git a/lib/fluent/plugin_helper/server.rb b/lib/fluent/plugin_helper/server.rb index 35f478942a..0f7e277fec 100644 --- a/lib/fluent/plugin_helper/server.rb +++ b/lib/fluent/plugin_helper/server.rb @@ -780,7 +780,7 @@ def on_writable @mutex.synchronize do # Consider write_nonblock with {exception: false} when IO::WaitWritable error happens frequently. written_bytes = @_handler_socket.write_nonblock(@_handler_write_buffer) - @_handler_write_buffer.slice!(0, written_bytes) + @_handler_write_buffer = @_handler_write_buffer.slice(written_bytes..) end # No need to call `super` in a synchronized context because TLSServer doesn't use the inner buffer(::IO::Buffer) of Coolio::IO.