Skip to content

Commit cf09e6b

Browse files
author
Dave Abrahams
committed
[stdlib] UTF8View: count by iterating
The fancy code didn't turn out to be any faster.
1 parent dd3fb9b commit cf09e6b

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

stdlib/public/core/StringUTF8.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,8 @@ extension String.UTF8View.Iterator : IteratorProtocol {
492492
extension String.UTF8View {
493493
public var count: Int {
494494
if _fastPath(_core.isASCII) { return _core.count }
495-
defer { _fixLifetime(_core) }
496-
if _fastPath(_core._unmanagedUTF16 != nil), let b = _core._unmanagedUTF16 {
497-
var result = 0
498-
UTF8._transcode(b, from: UTF16.self) { result += $0.count }
499-
return result
500-
}
501495
var result = 0
502-
UTF8._transcode(_core, from: UTF16.self) { result += $0.count }
496+
for _ in self { result += 1 }
503497
return result
504498
}
505499
}

0 commit comments

Comments
 (0)