@@ -141,34 +141,6 @@ internal struct _NormalizedUTF8CodeUnitIterator: IteratorProtocol {
141
141
142
142
return utf8Buffer [ bufferIndex]
143
143
}
144
-
145
- internal mutating func compare(
146
- with other: _NormalizedUTF8CodeUnitIterator
147
- ) -> _StringComparisonResult {
148
- var mutableOther = other
149
-
150
- for cu in self {
151
- if let otherCU = mutableOther. next ( ) {
152
- let result = _lexicographicalCompare ( cu, otherCU)
153
- if result == . equal {
154
- continue
155
- } else {
156
- return result
157
- }
158
- } else {
159
- //other returned nil, we are greater
160
- return . greater
161
- }
162
- }
163
-
164
- //we ran out of code units, either we are equal, or only we ran out and
165
- //other is greater
166
- if let _ = mutableOther. next ( ) {
167
- return . less
168
- } else {
169
- return . equal
170
- }
171
- }
172
144
}
173
145
174
146
extension _NormalizedUTF8CodeUnitIterator : Sequence { }
@@ -463,16 +435,6 @@ extension _NormalizedUTF8CodeUnitIterator_2 {
463
435
@inline ( __always)
464
436
@_effects ( releasenone)
465
437
private mutating func fastPathFill( ) -> ( numRead: Int , numWritten: Int ) {
466
- // Quick check if a scalar is NFC and a segment starter
467
- @inline ( __always) func isNFCStarter( _ scalar: Unicode . Scalar ) -> Bool {
468
- // Fast-path: All scalars up through U+02FF are NFC and have boundaries
469
- // before them
470
- if scalar. value < 0x300 { return true }
471
-
472
- // Otherwise, consult the properties
473
- return scalar. _hasNormalizationBoundaryBefore && scalar. _isNFCQCYes
474
- }
475
-
476
438
// TODO: Additional fast-path: All CCC-ascending NFC_QC segments are NFC
477
439
// TODO: Just freakin do normalization and don't bother with ICU
478
440
var outputCount = 0
@@ -490,7 +452,7 @@ extension _NormalizedUTF8CodeUnitIterator_2 {
490
452
491
453
if _slowPath (
492
454
!utf8. hasNormalizationBoundary ( before: inputCount &+ len)
493
- || !isNFCStarter ( scalar)
455
+ || !scalar. _isNFCStarter
494
456
) {
495
457
break
496
458
}
@@ -516,7 +478,7 @@ extension _NormalizedUTF8CodeUnitIterator_2 {
516
478
if _slowPath (
517
479
!gutsSlice. foreignHasNormalizationBoundary (
518
480
before: startIdx. encoded ( offsetBy: len) )
519
- || !isNFCStarter ( scalar)
481
+ || !scalar. _isNFCStarter
520
482
) {
521
483
break
522
484
}
@@ -577,29 +539,22 @@ extension _NormalizedUTF8CodeUnitIterator_2 {
577
539
578
540
@_effects ( readonly)
579
541
internal mutating func compare(
580
- with other: _NormalizedUTF8CodeUnitIterator_2
581
- ) -> _StringComparisonResult {
582
- var iter = self
542
+ with other: _NormalizedUTF8CodeUnitIterator_2 ,
543
+ expecting : _StringComparisonResult
544
+ ) -> Bool {
583
545
var mutableOther = other
584
546
585
- while let cu = iter. next ( ) {
586
- if let otherCU = mutableOther. next ( ) {
587
- let result = _lexicographicalCompare ( cu, otherCU)
588
- if result == . equal {
589
- continue
590
- }
591
- return result
547
+ for cu in self {
548
+ guard let otherCU = mutableOther. next ( ) else {
549
+ // We have more code units, therefore we are greater
550
+ return false
592
551
}
593
- //other returned nil, we are greater
594
- return . greater
552
+ if cu == otherCU { continue }
553
+ return expecting == . less ? cu < otherCU : false
595
554
}
596
555
597
- //we ran out of code units, either we are equal, or only we ran out and
598
- //other is greater
599
- if let _ = mutableOther. next ( ) {
600
- return . less
601
- }
602
- return . equal
556
+ // We have exhausted our code units. We are less if there's more remaining
557
+ return mutableOther. next ( ) == nil ? expecting == . equal : expecting == . less
603
558
}
604
559
}
605
560
0 commit comments