Skip to content

Commit 7da3f79

Browse files
authored
Merge pull request #4294 from isimluk/minor-perf
Minor performance improvements
2 parents eb30a6e + a21dcab commit 7da3f79

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

lib/fluent/plugin/buffer/file_chunk.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def restore_metadata_with_new_format(chunk)
399399
end
400400

401401
if chunk.slice(0, 2) == BUFFER_HEADER
402-
size = chunk.slice(2, 4).unpack('N').first
402+
size = chunk.slice(2, 4).unpack1('N')
403403
if size
404404
return Fluent::MessagePackFactory.msgpack_unpacker(symbolize_keys: true).feed(chunk.slice(6, size)).read rescue nil
405405
end

lib/fluent/plugin/buffer/file_single_chunk.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,16 @@ def file_rename(file, old_path, new_path, callback = nil)
238238
callback.call(file) if callback
239239
end
240240

241-
URI_PARSER = URI::Parser.new
242241
ESCAPE_REGEXP = /[^-_.a-zA-Z0-9]/n
243242

244243
def encode_key(metadata)
245244
k = @key ? metadata.variables[@key] : metadata.tag
246245
k ||= ''
247-
URI_PARSER.escape(k, ESCAPE_REGEXP)
246+
URI::DEFAULT_PARSER.escape(k, ESCAPE_REGEXP)
248247
end
249248

250249
def decode_key(key)
251-
URI_PARSER.unescape(key)
250+
URI::DEFAULT_PARSER.unescape(key)
252251
end
253252

254253
def create_new_chunk(path, metadata, perm)

lib/fluent/registry.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,31 @@ def search(type)
6060
# search from additional plugin directories
6161
if @dir_search_prefix
6262
path = "#{@dir_search_prefix}#{type}"
63-
files = @paths.map { |lp|
63+
files = @paths.filter_map { |lp|
6464
lpath = File.expand_path(File.join(lp, "#{path}.rb"))
6565
File.exist?(lpath) ? lpath : nil
66-
}.compact
66+
}
6767
unless files.empty?
6868
# prefer newer version
69-
require files.sort.last
69+
require files.max
7070
return
7171
end
7272
end
7373

7474
path = "#{@search_prefix}#{type}"
7575

7676
# prefer LOAD_PATH than gems
77-
files = $LOAD_PATH.map { |lp|
77+
files = $LOAD_PATH.filter_map { |lp|
7878
if lp == FLUENT_LIB_PATH
7979
nil
8080
else
8181
lpath = File.expand_path(File.join(lp, "#{path}.rb"))
8282
File.exist?(lpath) ? lpath : nil
8383
end
84-
}.compact
84+
}
8585
unless files.empty?
8686
# prefer newer version
87-
require files.sort.last
87+
require files.max
8888
return
8989
end
9090

lib/fluent/unique_id.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def self.generate
2323
end
2424

2525
def self.hex(unique_id)
26-
unique_id.unpack('H*').first
26+
unique_id.unpack1('H*')
2727
end
2828

2929
module Mixin

0 commit comments

Comments
 (0)