File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,31 @@ internal func _stringCompare(
18
18
_ lhs: _StringGuts , _ rhs: _StringGuts , expecting: _StringComparisonResult
19
19
) -> Bool {
20
20
if lhs. rawBits == rhs. rawBits { return expecting == . equal }
21
+ return _stringCompareWithSmolCheck ( lhs, rhs, expecting: expecting)
22
+ }
23
+
24
+ @usableFromInline
25
+ @_effects ( readonly)
26
+ internal func _stringCompareWithSmolCheck(
27
+ _ lhs: _StringGuts , _ rhs: _StringGuts , expecting: _StringComparisonResult
28
+ ) -> Bool {
29
+ // ASCII small-string fast-path:
30
+ if lhs. isSmallASCII && rhs. isSmallASCII {
31
+ let lhsRaw = lhs. asSmall. _storage
32
+ let rhsRaw = rhs. asSmall. _storage
33
+
34
+ if lhsRaw. 0 != rhsRaw. 0 {
35
+ return _lexicographicalCompare (
36
+ lhsRaw. 0 . byteSwapped, rhsRaw. 0 . byteSwapped, expecting: expecting)
37
+ }
38
+ return _lexicographicalCompare (
39
+ lhsRaw. 1 . byteSwapped, rhsRaw. 1 . byteSwapped, expecting: expecting)
40
+ }
41
+
21
42
return _stringCompareInternal ( lhs, rhs, expecting: expecting)
22
43
}
23
44
45
+ @inline ( never) // Keep `_stringCompareWithSmolCheck` fast-path fast
24
46
@usableFromInline
25
47
@_effects ( readonly)
26
48
internal func _stringCompareInternal(
Original file line number Diff line number Diff line change @@ -90,6 +90,10 @@ extension _StringGuts {
90
90
@inline ( __always) get { return _object. isSmall }
91
91
}
92
92
93
+ internal var isSmallASCII : Bool {
94
+ @inline ( __always) get { return _object. isSmall && _object. smallIsASCII }
95
+ }
96
+
93
97
@inlinable
94
98
internal var asSmall : _SmallString {
95
99
@inline ( __always) get { return _SmallString ( _object) }
You can’t perform that action at this time.
0 commit comments