@@ -484,32 +484,28 @@ extension String.UTF8View.Iterator : IteratorProtocol {
484
484
485
485
@_inlineable // FIXME(sil-serialize-all)
486
486
public mutating func next( ) -> Unicode . UTF8 . CodeUnit ? {
487
+ if _slowPath ( _nextOffset == _endOffset) {
488
+ if _slowPath ( _buffer. isEmpty) {
489
+ return nil
490
+ }
491
+ }
492
+ if _guts. isASCII {
493
+ defer { _nextOffset += 1 }
494
+ return _guts. _unmanagedASCIIView. buffer [ _nextOffset]
495
+ }
496
+
487
497
if _fastPath ( !_buffer. isEmpty) {
488
498
return _buffer. removeFirst ( )
489
499
}
490
- if _nextOffset == _endOffset { return nil }
491
500
return _fillBuffer ( )
492
501
}
493
502
494
503
@_versioned
495
504
@inline ( never)
496
505
internal mutating func _fillBuffer( ) -> Unicode . UTF8 . CodeUnit {
497
- _sanityCheck ( _buffer. isEmpty)
498
- _sanityCheck ( _nextOffset < _endOffset)
506
+ _sanityCheck ( !_guts. isASCII, " next() already checks for known ASCII " )
499
507
defer { _fixLifetime ( _guts) }
500
- if _guts. isASCII {
501
- // FIXME: Measure if it's worth inlining this path
502
- let ascii = _guts. _unmanagedASCIIView. buffer
503
- let result = ascii [ _nextOffset]
504
- _nextOffset += 1
505
- let fillCount = min ( _buffer. capacity, _endOffset - _nextOffset)
506
- for _ in 0 ..< fillCount {
507
- _buffer. append ( ascii [ _nextOffset] )
508
- _nextOffset += 1
509
- }
510
- return result
511
- }
512
- if _guts. _isContiguous {
508
+ if _fastPath ( _guts. _isContiguous) {
513
509
return _fillBuffer ( from: _guts. _unmanagedUTF16View)
514
510
}
515
511
return _fillBuffer ( from: _guts. _asOpaque ( ) )
0 commit comments