Skip to content

Commit b057000

Browse files
committed
Speedup duplicate rule detection
1 parent 3b5953c commit b057000

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/puppet/provider/firewall/iptables.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,11 @@ def exists?
421421
end
422422

423423
def duplicate_rule?(rule)
424-
rules = self.class.instances
425-
system_rule_count = Hash.new(0)
426-
rules.each { |r| system_rule_count[r.name] += 1 }
427-
duplicate_rules = rules.select { |r| system_rule_count[r.name] > 1 }
428-
duplicate_rules.select { |r| r.name == rule }.any?
424+
self.class.instances.each_with_object({ count: 0 }) do |r, obj|
425+
obj[:count] += 1 if r.name == rule
426+
return true if obj[:count] > 1
427+
end
428+
false
429429
end
430430

431431
# Flush the property hash once done.

0 commit comments

Comments
 (0)