Skip to content

Commit f6b67f3

Browse files
authored
Declare some FloatingPointSign members explicitly for @inlinable (swiftlang#16043)
The compiler can synthesize these, but it doesn't mark them @inlinable, since in the general case they're just a "default" implementation and not "the only implementation forever". But for a two-element enum that's based on a part of IEEE 754, it's probably safe to assume this is the only implementation forever, and that can be important for performance. https://bugs.swift.org/browse/SR-7094
1 parent 1a57377 commit f6b67f3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

stdlib/public/core/FloatingPoint.swift.gyb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,31 @@ public enum FloatingPointSign: Int {
12251225

12261226
/// The sign for a negative value.
12271227
case minus
1228+
1229+
// Explicit declarations of otherwise-synthesized members to make them
1230+
// @inlinable, promising that we will never change the implementation.
1231+
1232+
@inlinable
1233+
public init?(rawValue: Int) {
1234+
switch rawValue {
1235+
case 0: self = .plus
1236+
case 1: self = .minus
1237+
default: return nil
1238+
}
1239+
}
1240+
1241+
@inlinable
1242+
public var rawValue: Int {
1243+
switch self {
1244+
case .plus: return 0
1245+
case .minus: return 1
1246+
}
1247+
}
1248+
1249+
@inlinable
1250+
public static func ==(a: FloatingPointSign, b: FloatingPointSign) -> Bool {
1251+
return a.rawValue == b.rawValue
1252+
}
12281253
}
12291254

12301255
/// The IEEE 754 floating-point classes.

0 commit comments

Comments
 (0)