File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -319,21 +319,26 @@ open class ProcessInfo: NSObject {
319
319
}
320
320
321
321
// These are internal access for testing
322
- static func countCoreIds( cores: Substring ) -> Int {
322
+ static func countCoreIds( cores: Substring ) -> Int ? {
323
323
let ids = cores. split ( separator: " - " , maxSplits: 1 )
324
324
guard let first = ids. first. flatMap ( { Int ( $0, radix: 10 ) } ) ,
325
325
let last = ids. last. flatMap ( { Int ( $0, radix: 10 ) } ) ,
326
326
last >= first
327
- else { preconditionFailure ( " cpuset format is incorrect " ) }
327
+ else {
328
+ return nil
329
+ }
328
330
return 1 + last - first
329
331
}
330
332
331
333
static func coreCount( cpuset cpusetPath: String ) -> Int ? {
332
334
guard let cpuset = try ? firstLineOfFile ( path: cpusetPath) . split ( separator: " , " ) ,
333
335
!cpuset. isEmpty
334
336
else { return nil }
335
-
336
- return cpuset. map ( countCoreIds) . reduce ( 0 , + )
337
+ if let first = cpuset. first, let count = countCoreIds ( cores: first) {
338
+ return count
339
+ } else {
340
+ return nil
341
+ }
337
342
}
338
343
339
344
static func coreCount( quota quotaPath: String , period periodPath: String ) -> Int ? {
You can’t perform that action at this time.
0 commit comments