@@ -209,11 +209,11 @@ extension _UnmanagedString where CodeUnit : FixedWidthInteger & UnsignedInteger
209
209
}
210
210
211
211
extension _UnmanagedOpaqueString {
212
- internal func _findDiffIdx( _ other: _StringGuts
212
+ internal func _findDiffIdx( _ other: _StringGuts , _ otherRange : Range < Int >
213
213
) -> Int {
214
- let count = Swift . min ( self . count, other . count)
214
+ let count = Swift . min ( self . count, otherRange . count)
215
215
for idx in 0 ..< count {
216
- guard self [ idx] == other [ idx] else {
216
+ guard self [ idx] == other [ idx + otherRange . lowerBound ] else {
217
217
return idx
218
218
}
219
219
}
@@ -552,13 +552,13 @@ extension _UnmanagedOpaqueString {
552
552
let selfCount = selfRange. count
553
553
let otherCount = otherRange. count
554
554
let count = Swift . min ( selfCount, otherCount)
555
- let idx = self . _findDiffIdx ( other)
555
+ let idx = self [ selfRange ] . _findDiffIdx ( other, otherRange )
556
556
if idx == count {
557
557
return _lexicographicalCompare ( selfCount, otherCount)
558
558
}
559
559
560
560
let selfCU = self [ idx]
561
- let otherCU = other [ idx]
561
+ let otherCU = other [ idx + otherRange . lowerBound ]
562
562
563
563
//
564
564
// Fast path: if one is ASCII, we can often compare the code units directly.
@@ -587,7 +587,7 @@ extension _UnmanagedOpaqueString {
587
587
}
588
588
589
589
return self . _compareOpaquePathological (
590
- other, startingFrom: Swift . max ( 0 , idx- 1 ) )
590
+ other, otherRange , startingFrom: Swift . max ( 0 , idx- 1 ) )
591
591
}
592
592
593
593
if selfIsASCII && selfIsSingleSegmentScalar
@@ -600,19 +600,20 @@ extension _UnmanagedOpaqueString {
600
600
}
601
601
602
602
return self . _compareOpaquePathological (
603
- other, startingFrom: Swift . max ( 0 , idx- 1 )
603
+ other, otherRange , startingFrom: Swift . max ( 0 , idx- 1 )
604
604
)
605
605
}
606
606
607
607
@inline ( never)
608
608
func _compareOpaquePathological(
609
- _ other: _StringGuts , startingFrom: Int
609
+ _ other: _StringGuts , _ otherRange: Range < Int > ,
610
+ startingFrom: Int
610
611
) -> _Ordering {
611
612
// Compare by pulling in a segment at a time, normalizing then comparing
612
613
// individual code units
613
614
var selfIterator = _NormalizedCodeUnitIterator ( self , startIndex: startingFrom)
614
615
return selfIterator. compare ( with:
615
- _NormalizedCodeUnitIterator ( other, startIndex: startingFrom)
616
+ _NormalizedCodeUnitIterator ( other, otherRange , startIndex: startingFrom)
616
617
)
617
618
}
618
619
}
0 commit comments