|
15 | 15 | // made in sync.
|
16 | 16 | @_alwaysEmitIntoClient
|
17 | 17 | internal func _parseASCIIDigits<
|
18 |
| - UTF8CodeUnits: Sequence, Result: FixedWidthInteger |
| 18 | + UTF8CodeUnits: Collection, Result: FixedWidthInteger |
19 | 19 | >(
|
20 | 20 | _ codeUnits: UTF8CodeUnits, radix: Int, isNegative: Bool
|
21 | 21 | ) -> Result? where UTF8CodeUnits.Element == UInt8 {
|
22 | 22 | _internalInvariant(radix >= 2 && radix <= 36)
|
| 23 | + guard _fastPath(!codeUnits.isEmpty) else { return nil } |
23 | 24 | let multiplicand = Result(radix)
|
24 | 25 | var result = 0 as Result
|
25 | 26 | if radix <= 10 {
|
@@ -74,6 +75,7 @@ internal func _parseASCIIDigits<Result: FixedWidthInteger>(
|
74 | 75 | _ codeUnits: UnsafeBufferPointer<UInt8>, radix: Int, isNegative: Bool
|
75 | 76 | ) -> Result? {
|
76 | 77 | _internalInvariant(radix >= 2 && radix <= 36)
|
| 78 | + guard _fastPath(!codeUnits.isEmpty) else { return nil } |
77 | 79 | let multiplicand = Result(radix)
|
78 | 80 | var result = 0 as Result
|
79 | 81 | if radix <= 10 {
|
@@ -191,6 +193,7 @@ extension FixedWidthInteger {
|
191 | 193 | /// - radix: The radix, or base, to use for converting `text` to an integer
|
192 | 194 | /// value. `radix` must be in the range `2...36`. The default is 10.
|
193 | 195 | @inlinable
|
| 196 | + @inline(__always) |
194 | 197 | public init?<S: StringProtocol>(_ text: S, radix: Int = 10) {
|
195 | 198 | _precondition(2...36 ~= radix, "Radix not in range 2...36")
|
196 | 199 | guard _fastPath(!text.isEmpty) else { return nil }
|
|
0 commit comments