summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCooper Lees <me@cooperlees.com>2020-06-30 10:38:17 -0700
committerGitHub <noreply@github.com>2020-06-30 10:38:17 -0700
commitf8e4e280066451036a8a2ede3f04bf24e89c740d (patch)
tree860283776ba86d00a52283f33d4d3e9ab0acf253
parent8122985f32431e8eb5a3355951f56e253b164c37 (diff)
downloadohai-f8e4e280066451036a8a2ede3f04bf24e89c740d.tar.gz
Move regex out of the loop
Save regex lookup each iteration. This is hot. Co-authored-by: pete higgins <pete@peterhiggins.org>
-rw-r--r--lib/ohai/plugins/linux/network.rb5
1 files changed, 1 insertions, 4 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 42dba4ab..6458db85 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -105,13 +105,10 @@ Ohai.plugin(:Network) do
route_entry = Mash.new(destination: route_dest,
family: family[:name])
%w{via scope metric proto src}.each do |k|
- if k == "via" && route_ending =~ /\bvia\sinet6\s+([^\s]+)/
- route_entry[k] = $1
- next
- end
# http://rubular.com/r/pwTNp65VFf
route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)/
end
+ route_entry["via"] = $1 if route_ending =~ /\bvia\s+inet6\s+([^\s]+)/
# a sanity check, especially for Linux-VServer, OpenVZ and LXC:
# don't report the route entry if the src address isn't set on the node