@@ -16,25 +16,36 @@ public enum AppExecutionMode: Int32, Codable, Equatable, CaseIterable{
1616
1717 ///Gets if the current process is running natively or emulated
1818 static func current( ) -> AppExecutionMode {
19- var ret : Int32 = 0
20- var size = ret . bitWidth / 8
21-
22- let result = sysctlbyname ( " sysctl.proc_translated " , & ret , & size , nil , 0 )
19+ //stores the obtained value so useless re-detections are avoided since this value isn't supposed to change at execution time
20+ struct MEM {
21+ static var state : AppExecutionMode ? = nil
22+ }
2323
24- if result == - 1 {
25- if ( errno == ENOENT) {
26- return AppExecutionMode . native
24+ if MEM . state == nil {
25+ var ret : Int32 = 0
26+ var size = ret. bitWidth / 8
27+
28+ let result = sysctlbyname ( " sysctl.proc_translated " , & ret, & size, nil , 0 )
29+
30+ if result == - 1 {
31+ if ( errno == ENOENT) {
32+ MEM . state = AppExecutionMode . native
33+ } else {
34+ MEM . state = AppExecutionMode . unkown
35+ }
36+ } else {
37+ MEM . state = AppExecutionMode ( rawValue: ret) ?? . unkown
2738 }
28- return AppExecutionMode . unkown
39+
2940 }
3041
31- return AppExecutionMode ( rawValue : ret ) ?? . unkown
42+ return MEM . state!
3243 }
3344}
3445
3546///This enum is used to make more conveniente the detection of the actual cpu architecture
3647public enum CpuArchitecture : String , Codable , Equatable , CaseIterable {
37- case ppc = " ppc " //belive it or not but there are swift compilers for ppc out there
48+ case ppc = " ppc " //belive it or not but there are swift compilers for ppc out there, so a bunch of PPC targets are included, if one is missing feel free to add it using a pull request.
3849 case ppcG1 = " ppc601 "
3950 case ppcG2 = " ppc604 "
4051 case ppcG3 = " ppc750 "
@@ -60,7 +71,7 @@ public enum CpuArchitecture: String, Codable, Equatable, CaseIterable{
6071
6172 ///Gets the current architecture used by the current process
6273 public static func current( ) -> CpuArchitecture ? {
63- //stores the obtained value so useless re-detections are avoided
74+ //stores the obtained value so useless re-detections are avoided since this value isn't supposed to change at execution time
6475 struct MEM {
6576 static var state : CpuArchitecture ? = nil
6677 }
0 commit comments