File tree Expand file tree Collapse file tree 5 files changed +7
-34
lines changed Expand file tree Collapse file tree 5 files changed +7
-34
lines changed Original file line number Diff line number Diff line change @@ -301,19 +301,13 @@ extension _StringGuts {
301
301
// Encoding
302
302
extension _StringGuts {
303
303
/// Returns whether this string has a UTF-8 storage representation.
304
+ /// If this returns false, then the string is encoded in UTF-16.
304
305
///
305
306
/// This always returns a value corresponding to the string's actual encoding.
306
307
@_alwaysEmitIntoClient
307
308
@inline ( __always)
308
309
internal var isUTF8 : Bool { _object. isUTF8 }
309
310
310
- /// Returns whether this string has a UTF-16 storage representation.
311
- ///
312
- /// This always returns a value corresponding to the string's actual encoding.
313
- @_alwaysEmitIntoClient
314
- @inline ( __always)
315
- internal var isUTF16 : Bool { _object. isUTF16 }
316
-
317
311
@_alwaysEmitIntoClient // Swift 5.7
318
312
@inline ( __always)
319
313
internal func markEncoding( _ i: String . Index ) -> String . Index {
Original file line number Diff line number Diff line change @@ -466,10 +466,9 @@ extension _StringGuts {
466
466
_internalInvariant (
467
467
subrange. lowerBound >= startIndex && subrange. upperBound <= endIndex)
468
468
469
- if _slowPath ( isUTF16) {
470
- // UTF-16 (i.e., foreign) string. The mutation will convert this to the
471
- // native UTF-8 encoding, so we need to do some extra work to preserve our
472
- // bounds.
469
+ guard _slowPath ( isUTF8) else {
470
+ // UTF-16 string. The mutation will convert this to the native UTF-8
471
+ // encoding, so we need to do some extra work to preserve our bounds.
473
472
let utf8StartOffset = String ( self ) . utf8. distance (
474
473
from: self . startIndex, to: startIndex)
475
474
let oldUTF8Count = String ( self ) . utf8. distance (
Original file line number Diff line number Diff line change @@ -481,24 +481,12 @@ extension String.Index {
481
481
}
482
482
483
483
@_alwaysEmitIntoClient // Swift 5.7
484
- internal func _copyEncoding ( from index: Self ) -> Self {
484
+ internal func _copyingEncoding ( from index: Self ) -> Self {
485
485
let mask = Self . __utf8Bit | Self . __utf16Bit
486
486
return Self ( ( _rawBits & ~ mask) | ( index. _rawBits & mask) )
487
487
}
488
488
}
489
489
490
- extension String . Index {
491
- @_alwaysEmitIntoClient @inline ( __always) // Swift 5.7
492
- internal var _isUTF8CharacterIndex : Bool {
493
- _canBeUTF8 && _isCharacterAligned
494
- }
495
-
496
- @_alwaysEmitIntoClient @inline ( __always) // Swift 5.7
497
- internal var _isUTF8ScalarIndex : Bool {
498
- _canBeUTF8 && _isScalarAligned
499
- }
500
- }
501
-
502
490
extension String . Index : Equatable {
503
491
@inlinable @inline ( __always)
504
492
public static func == ( lhs: String . Index , rhs: String . Index ) -> Bool {
Original file line number Diff line number Diff line change @@ -1009,6 +1009,7 @@ extension _StringObject {
1009
1009
}
1010
1010
1011
1011
/// Returns whether this string has a UTF-8 storage representation.
1012
+ /// If this returns false, then the string is encoded in UTF-16.
1012
1013
///
1013
1014
/// This always returns a value corresponding to the string's actual encoding.
1014
1015
@_alwaysEmitIntoClient
@@ -1030,15 +1031,6 @@ extension _StringObject {
1030
1031
providesFastUTF8 || _countAndFlags. isForeignUTF8
1031
1032
}
1032
1033
1033
- /// Returns whether this string has a UTF-16 storage representation.
1034
- ///
1035
- /// This always returns a value corresponding to the string's actual encoding.
1036
- @_alwaysEmitIntoClient
1037
- @inline ( __always) // Swift 5.7
1038
- internal var isUTF16 : Bool {
1039
- !isUTF8
1040
- }
1041
-
1042
1034
// Get access to fast UTF-8 contents for large strings which provide it.
1043
1035
@inlinable @inline ( __always)
1044
1036
internal var fastUTF8 : UnsafeBufferPointer < UInt8 > {
Original file line number Diff line number Diff line change @@ -167,7 +167,7 @@ extension _StringGuts {
167
167
result = idx
168
168
} else {
169
169
// TODO(String performance): isASCII check
170
- result = scalarAlignSlow ( idx) . _scalarAligned. _copyEncoding ( from: idx)
170
+ result = scalarAlignSlow ( idx) . _scalarAligned. _copyingEncoding ( from: idx)
171
171
}
172
172
173
173
_internalInvariant ( isOnUnicodeScalarBoundary ( result) ,
You can’t perform that action at this time.
0 commit comments