Move caching from sysctl_bool to sysctl_n
This commit is contained in:
parent
37c394f828
commit
1255f7b894
@ -15,8 +15,7 @@ module MacCPUs
|
|||||||
# These methods use info spewed out by sysctl.
|
# These methods use info spewed out by sysctl.
|
||||||
# Look in <mach/machine.h> for decoding info.
|
# Look in <mach/machine.h> for decoding info.
|
||||||
def type
|
def type
|
||||||
@type ||= sysctl_int("hw.cputype")
|
case sysctl_int("hw.cputype")
|
||||||
case @type
|
|
||||||
when 7
|
when 7
|
||||||
:intel
|
:intel
|
||||||
when 18
|
when 18
|
||||||
@ -28,7 +27,7 @@ module MacCPUs
|
|||||||
|
|
||||||
def family
|
def family
|
||||||
if intel?
|
if intel?
|
||||||
case @intel_family ||= sysctl_int("hw.cpufamily")
|
case sysctl_int("hw.cpufamily")
|
||||||
when 0x73d67300 # Yonah: Core Solo/Duo
|
when 0x73d67300 # Yonah: Core Solo/Duo
|
||||||
:core
|
:core
|
||||||
when 0x426f69ef # Merom: Core 2 Duo
|
when 0x426f69ef # Merom: Core 2 Duo
|
||||||
@ -49,7 +48,7 @@ module MacCPUs
|
|||||||
:dunno
|
:dunno
|
||||||
end
|
end
|
||||||
elsif ppc?
|
elsif ppc?
|
||||||
case @ppc_family ||= sysctl_int("hw.cpusubtype")
|
case sysctl_int("hw.cpusubtype")
|
||||||
when 9
|
when 9
|
||||||
:g3 # PowerPC 750
|
:g3 # PowerPC 750
|
||||||
when 10
|
when 10
|
||||||
@ -67,15 +66,15 @@ module MacCPUs
|
|||||||
end
|
end
|
||||||
|
|
||||||
def extmodel
|
def extmodel
|
||||||
@extmodel ||= sysctl_int("machdep.cpu.extmodel")
|
sysctl_int("machdep.cpu.extmodel")
|
||||||
end
|
end
|
||||||
|
|
||||||
def cores
|
def cores
|
||||||
@cores ||= sysctl_int("hw.ncpu")
|
sysctl_int("hw.ncpu")
|
||||||
end
|
end
|
||||||
|
|
||||||
def bits
|
def bits
|
||||||
@bits ||= sysctl_bool("hw.cpu64bit_capable") ? 64 : 32
|
sysctl_bool("hw.cpu64bit_capable") ? 64 : 32
|
||||||
end
|
end
|
||||||
|
|
||||||
def arch_32_bit
|
def arch_32_bit
|
||||||
@ -138,10 +137,8 @@ module MacCPUs
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def sysctl_bool(property)
|
def sysctl_bool(key)
|
||||||
(@properties ||= {}).fetch(property) do
|
sysctl_int(key) == 1 && $?.success?
|
||||||
@properties[property] = sysctl_int(property) == 1 && $?.success?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sysctl_int(key)
|
def sysctl_int(key)
|
||||||
@ -149,6 +146,8 @@ module MacCPUs
|
|||||||
end
|
end
|
||||||
|
|
||||||
def sysctl_n(key)
|
def sysctl_n(key)
|
||||||
Utils.popen_read("/usr/sbin/sysctl", "-n", key)
|
(@properties ||= {}).fetch(key) do
|
||||||
|
@properties[key] = Utils.popen_read("/usr/sbin/sysctl", "-n", key)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user