Skip to content

Commit aaafc72

Browse files
committed
Type constants as Int to reduce type inference cost.
1 parent a07c193 commit aaafc72

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Sources/Foundation/NSData.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,14 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
458458
if writeOptionsMask.contains(.withoutOverwriting) {
459459
flags |= O_EXCL
460460
}
461+
462+
// NOTE: Each flag such as `S_IRUSR` may be literal depends on the system.
463+
// Without explicity type them as `Int`, type inference will not complete in reasonable time
464+
// and the compiler will throw an error.
461465
#if os(Windows)
462-
let createMode = Int(ucrt.S_IREAD | ucrt.S_IWRITE)
466+
let createMode = Int(ucrt.S_IREAD) | Int(ucrt.S_IWRITE)
463467
#else
464-
let createMode = Int(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
468+
let createMode = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH)
465469
#endif
466470
guard let fh = FileHandle(path: path, flags: flags, createMode: createMode) else {
467471
throw _NSErrorWithErrno(errno, reading: false, path: path)

0 commit comments

Comments
 (0)