Skip to content

Commit a9c57c3

Browse files
committed
[stdlib] Make FixedWidthInteger.init?(_:radix:) always inlined, and fix a think-o.
1 parent ad992f4 commit a9c57c3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

stdlib/public/core/IntegerParsing.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
// made in sync.
1616
@_alwaysEmitIntoClient
1717
internal func _parseASCIIDigits<
18-
UTF8CodeUnits: Sequence, Result: FixedWidthInteger
18+
UTF8CodeUnits: Collection, Result: FixedWidthInteger
1919
>(
2020
_ codeUnits: UTF8CodeUnits, radix: Int, isNegative: Bool
2121
) -> Result? where UTF8CodeUnits.Element == UInt8 {
2222
_internalInvariant(radix >= 2 && radix <= 36)
23+
guard _fastPath(!codeUnits.isEmpty) else { return nil }
2324
let multiplicand = Result(radix)
2425
var result = 0 as Result
2526
if radix <= 10 {
@@ -74,6 +75,7 @@ internal func _parseASCIIDigits<Result: FixedWidthInteger>(
7475
_ codeUnits: UnsafeBufferPointer<UInt8>, radix: Int, isNegative: Bool
7576
) -> Result? {
7677
_internalInvariant(radix >= 2 && radix <= 36)
78+
guard _fastPath(!codeUnits.isEmpty) else { return nil }
7779
let multiplicand = Result(radix)
7880
var result = 0 as Result
7981
if radix <= 10 {
@@ -191,6 +193,7 @@ extension FixedWidthInteger {
191193
/// - radix: The radix, or base, to use for converting `text` to an integer
192194
/// value. `radix` must be in the range `2...36`. The default is 10.
193195
@inlinable
196+
@inline(__always)
194197
public init?<S: StringProtocol>(_ text: S, radix: Int = 10) {
195198
_precondition(2...36 ~= radix, "Radix not in range 2...36")
196199
guard _fastPath(!text.isEmpty) else { return nil }

0 commit comments

Comments
 (0)