Skip to content

Commit

Permalink
Bail out early to avoid safe operator
Browse files Browse the repository at this point in the history
Also add some notes here that we should convert this to a filter_map
when we can as that's easier to read and faster.

Perf benchmarks from the tubes:

Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Sep 8, 2020
1 parent 3485634 commit 0834783
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/ohai/plugins/linux/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ def check_routing_table(family, iface, default_route_table)
# using a temporary var to hold routes and their interface name
def parse_routes(family, iface)
iface.collect do |i, iv|
iv[:routes]&.collect do |r|
next unless iv[:routes]

iv[:routes].collect do |r|
r.merge(dev: i) if r[:family] == family[:name]
end&.compact
end.compact.flatten
end.compact # @todo: when we drop ruby 2.6 this should be a filter_map
end.compact.flatten # @todo: when we drop ruby 2.6 this should be a filter_map
end

# determine layer 1 details for the interface using ethtool
Expand Down

0 comments on commit 0834783

Please sign in to comment.