Skip to content

Commit 0ba58de

Browse files
committed
[se-0405] improve fast path
1 parent 148a7e2 commit 0ba58de

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

stdlib/public/core/StringCreate.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,15 @@ extension String {
305305
_ input: UnsafeBufferPointer<Encoding.CodeUnit>,
306306
as encoding: Encoding.Type
307307
) -> String? {
308-
fast: // fast-path
309308
if encoding.CodeUnit.self == UInt8.self {
310309
let bytes = _identityCast(input, to: UnsafeBufferPointer<UInt8>.self)
311-
let isASCII: Bool
312310
if encoding.self == UTF8.self {
313311
guard case .success(let info) = validateUTF8(bytes) else { return nil }
314-
isASCII = info.isASCII
312+
return String._uncheckedFromUTF8(bytes, asciiPreScanResult: info.isASCII)
315313
} else if encoding.self == Unicode.ASCII.self {
316314
guard _allASCII(bytes) else { return nil }
317-
isASCII = true
318-
} else {
319-
break fast
315+
return String._uncheckedFromASCII(bytes)
320316
}
321-
return String._uncheckedFromUTF8(bytes, asciiPreScanResult: isASCII)
322317
}
323318

324319
// slow-path

0 commit comments

Comments
 (0)