@@ -937,26 +937,29 @@ extension _UnmanagedString where CodeUnit == UInt8 {
937
937
if _fastPath (
938
938
other. _parseRawScalar ( startingFrom: idx) . 0 . _isNormalizedSuperASCII
939
939
) {
940
- return . less
941
- }
942
- } else {
943
- let selfASCIIChar = UInt16 ( self [ idx] )
944
- _sanityCheck ( selfASCIIChar != otherCU, " should be different " )
945
- if idx+ 1 == other. count {
946
- return _lexicographicalCompare ( selfASCIIChar, otherCU)
947
- }
948
- if _fastPath ( other. hasNormalizationBoundary ( after: idx) ) {
949
- return _lexicographicalCompare ( selfASCIIChar, otherCU)
940
+ return . less
950
941
}
942
+
943
+ // Rare pathological case, e.g. Kelvin symbol
944
+ var selfIterator = _NormalizedCodeUnitIterator ( self )
945
+ return selfIterator. compare ( with: _NormalizedCodeUnitIterator ( other) )
946
+ }
947
+
948
+ let selfASCIIChar = UInt16 ( self [ idx] )
949
+ _sanityCheck ( selfASCIIChar != otherCU, " should be different " )
950
+ if idx+ 1 == other. count {
951
+ return _lexicographicalCompare ( selfASCIIChar, otherCU)
952
+ }
953
+ if _fastPath ( other. hasNormalizationBoundary ( after: idx) ) {
954
+ return _lexicographicalCompare ( selfASCIIChar, otherCU)
951
955
}
952
956
953
957
//
954
958
// Otherwise, need to normalize the segment and then compare
955
959
//
956
- let selfASCIIChar = UInt16 ( self [ idx] )
957
960
return _compareStringsPostSuffix (
958
- selfASCIIChar: selfASCIIChar, otherUTF16 : other [ idx... ]
959
- )
961
+ selfASCIIChar: selfASCIIChar, otherUTF16WithLeadingASCII : other [ idx... ]
962
+ )
960
963
}
961
964
}
962
965
@@ -1008,15 +1011,17 @@ extension BidirectionalCollection where Element == UInt16, SubSequence == Self {
1008
1011
}
1009
1012
}
1010
1013
1014
+ @inline ( never) // @outlined
1011
1015
private func _compareStringsPostSuffix(
1012
1016
selfASCIIChar: UInt16 ,
1013
- otherUTF16 : _UnmanagedString < UInt16 >
1017
+ otherUTF16WithLeadingASCII : _UnmanagedString < UInt16 >
1014
1018
) -> _Ordering {
1015
- let otherCU = otherUTF16 [ 0 ]
1019
+ let otherCU = otherUTF16WithLeadingASCII [ 0 ]
1016
1020
_sanityCheck ( otherCU <= 0x7F , " should be ASCII, otherwise no need to call " )
1017
1021
1018
- let segmentEndIdx = otherUTF16. _findNormalizationSegmentEnd ( startingFrom: 0 )
1019
- let segment = otherUTF16 [ ..< segmentEndIdx]
1022
+ let segmentEndIdx = otherUTF16WithLeadingASCII. _findNormalizationSegmentEnd (
1023
+ startingFrom: 0 )
1024
+ let segment = otherUTF16WithLeadingASCII [ ..< segmentEndIdx]
1020
1025
1021
1026
// Fast path: If prenormal, we're done.
1022
1027
if _Normalization. _prenormalQuickCheckYes ( segment) {
0 commit comments