Skip to content

Commit 3d8c29e

Browse files
committed
Early out for unequal NFC counts in String ==
1 parent 52e852a commit 3d8c29e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

stdlib/public/core/StringComparison.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ private func _stringCompareFastUTF8(
104104
bothNFC: Bool
105105
) -> Bool {
106106
if _fastPath(bothNFC) {
107+
/*
108+
If we know both Strings are NFC *and* we're just checking
109+
equality, then we can early-out without looking at the contents
110+
if the UTF8 counts are different (without the NFC req, equal
111+
characters can have different counts). It might be nicer to do
112+
this in _binaryCompare, but we have the information about what
113+
operation we're trying to do at this level.
114+
*/
115+
if expecting == .equal && utf8Left.count != utf8Right.count {
116+
return false
117+
}
107118
let cmp = _binaryCompare(utf8Left, utf8Right)
108119
return _lexicographicalCompare(cmp, 0, expecting: expecting)
109120
}

0 commit comments

Comments
 (0)