Skip to content

Commit

Permalink
Merge pull request #4294 from isimluk/minor-perf
Browse files Browse the repository at this point in the history
Minor performance improvements
  • Loading branch information
ashie authored Sep 11, 2023
2 parents eb30a6e + a21dcab commit 7da3f79
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/plugin/buffer/file_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def restore_metadata_with_new_format(chunk)
end

if chunk.slice(0, 2) == BUFFER_HEADER
size = chunk.slice(2, 4).unpack('N').first
size = chunk.slice(2, 4).unpack1('N')
if size
return Fluent::MessagePackFactory.msgpack_unpacker(symbolize_keys: true).feed(chunk.slice(6, size)).read rescue nil
end
Expand Down
5 changes: 2 additions & 3 deletions lib/fluent/plugin/buffer/file_single_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,16 @@ def file_rename(file, old_path, new_path, callback = nil)
callback.call(file) if callback
end

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

def encode_key(metadata)
k = @key ? metadata.variables[@key] : metadata.tag
k ||= ''
URI_PARSER.escape(k, ESCAPE_REGEXP)
URI::DEFAULT_PARSER.escape(k, ESCAPE_REGEXP)
end

def decode_key(key)
URI_PARSER.unescape(key)
URI::DEFAULT_PARSER.unescape(key)
end

def create_new_chunk(path, metadata, perm)
Expand Down
12 changes: 6 additions & 6 deletions lib/fluent/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,31 @@ def search(type)
# search from additional plugin directories
if @dir_search_prefix
path = "#{@dir_search_prefix}#{type}"
files = @paths.map { |lp|
files = @paths.filter_map { |lp|
lpath = File.expand_path(File.join(lp, "#{path}.rb"))
File.exist?(lpath) ? lpath : nil
}.compact
}
unless files.empty?
# prefer newer version
require files.sort.last
require files.max
return
end
end

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

# prefer LOAD_PATH than gems
files = $LOAD_PATH.map { |lp|
files = $LOAD_PATH.filter_map { |lp|
if lp == FLUENT_LIB_PATH
nil
else
lpath = File.expand_path(File.join(lp, "#{path}.rb"))
File.exist?(lpath) ? lpath : nil
end
}.compact
}
unless files.empty?
# prefer newer version
require files.sort.last
require files.max
return
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/unique_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.generate
end

def self.hex(unique_id)
unique_id.unpack('H*').first
unique_id.unpack1('H*')
end

module Mixin
Expand Down

0 comments on commit 7da3f79

Please sign in to comment.