Skip to content

Commit

Permalink
perf: avoid creating an extra list when iterating through values or keys
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Lukašík <[email protected]>
  • Loading branch information
isimluk committed Sep 26, 2023
1 parent 8555bbe commit 9942113
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/config/configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def merge_for_finalized(other)

def overwrite_defaults(other) # other is owner plugin's corresponding proxy
self.defaults = self.defaults.merge(other.defaults)
self.sections.keys.each do |section_key|
self.sections.each_key do |section_key|
if other.sections.has_key?(section_key)
self.sections[section_key].overwrite_defaults(other.sections[section_key])
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def initialize
super
# to simulate implicit 'attr_accessor' by config_param / config_section and its value by config_set_default
proxy = self.class.merged_configure_proxy
proxy.params.keys.each do |name|
proxy.params.each_key do |name|
next if name.to_s.start_with?('@')
if proxy.defaults.has_key?(name)
instance_variable_set("@#{name}".to_sym, proxy.defaults[name])
end
end
proxy.sections.keys.each do |name|
proxy.sections.each_key do |name|
next if name.to_s.start_with?('@')
subproxy = proxy.sections[name]
if subproxy.multi?
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/counter/mutex_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def synchronize(*keys)
if mutex.try_lock
locks[key] = mutex
else
locks.values.each(&:unlock)
locks.each_value(&:unlock)
locks = {} # flush locked keys
break
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/test/driver/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run(timeout: nil, start: true, shutdown: true, &block)

sleep_with_watching_threads = ->(){
if @instance.respond_to?(:_threads)
@instance._threads.values.each{|t| t.join(0) }
@instance._threads.each_value{|t| t.join(0) }
end
sleep 0.1
}
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/test/output_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def run(&block)
assert_equal(@expected_buffer, buffer)
end

lines.keys.each do |meta|
lines.each_key do |meta|
chunk = @instance.buffer.generate_chunk(meta).staged!
chunk.append(lines[meta])
begin
Expand Down

0 comments on commit 9942113

Please sign in to comment.