summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-02-25 14:21:39 -0800
committerTim Smith <tsmith@chef.io>2018-02-25 14:21:39 -0800
commit97c36db3b57e7e7d39707f1e63b3adb150d44add (patch)
treebc077ccbda48012a4602cca7f25ee151c4cb5914
parent508e12d33fed2f8be112291f947f0ad720c803d3 (diff)
downloadohai-97c36db3b57e7e7d39707f1e63b3adb150d44add.tar.gz
Simplify how we detect the OS Type (13x faster)
There's a few things here: 1) 99.99999999% of the time it's NT so check that first 2) There's no reason to convert to a string to compare when we know it's an Integer 3) .eql? is WAY slower than == and we don't have a complex data structure that requires .eql? Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/kernel.rb16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb
index 8d6372d7..da3d7727 100644
--- a/lib/ohai/plugins/kernel.rb
+++ b/lib/ohai/plugins/kernel.rb
@@ -59,14 +59,14 @@ Ohai.plugin(:Kernel) do
# windows
def os_lookup(sys_type)
- return "Unknown" if sys_type.to_s.eql?("0")
- return "Other" if sys_type.to_s.eql?("1")
- return "MSDOS" if sys_type.to_s.eql?("14")
- return "WIN3x" if sys_type.to_s.eql?("15")
- return "WIN95" if sys_type.to_s.eql?("16")
- return "WIN98" if sys_type.to_s.eql?("17")
- return "WINNT" if sys_type.to_s.eql?("18")
- return "WINCE" if sys_type.to_s.eql?("19")
+ return "WINNT" if sys_type == 18 # most likely so first
+ return "Unknown" if sys_type == 0
+ return "Other" if sys_type == 1
+ return "MSDOS" if sys_type == 14
+ return "WIN3x" if sys_type == 15
+ return "WIN95" if sys_type == 16
+ return "WIN98" if sys_type == 17
+ return "WINCE" if sys_type == 19
nil
end