Skip to content

Commit 847337e

Browse files
committed
[stdlib][cosmetics] Clean up unused/underused interfaces, update naming
There is little point to having `isUTF16` properties when they simply return `!isUTF8`; remove them. Rename `String.Index._copyEncoding(from:)` to `_copyingEncoding(from:)`.
1 parent 5f9828f commit 847337e

File tree

5 files changed

+7
-34
lines changed

5 files changed

+7
-34
lines changed

stdlib/public/core/StringGuts.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,13 @@ extension _StringGuts {
301301
// Encoding
302302
extension _StringGuts {
303303
/// Returns whether this string has a UTF-8 storage representation.
304+
/// If this returns false, then the string is encoded in UTF-16.
304305
///
305306
/// This always returns a value corresponding to the string's actual encoding.
306307
@_alwaysEmitIntoClient
307308
@inline(__always)
308309
internal var isUTF8: Bool { _object.isUTF8 }
309310

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-
317311
@_alwaysEmitIntoClient // Swift 5.7
318312
@inline(__always)
319313
internal func markEncoding(_ i: String.Index) -> String.Index {

stdlib/public/core/StringGutsRangeReplaceable.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,9 @@ extension _StringGuts {
466466
_internalInvariant(
467467
subrange.lowerBound >= startIndex && subrange.upperBound <= endIndex)
468468

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.
473472
let utf8StartOffset = String(self).utf8.distance(
474473
from: self.startIndex, to: startIndex)
475474
let oldUTF8Count = String(self).utf8.distance(

stdlib/public/core/StringIndex.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -481,24 +481,12 @@ extension String.Index {
481481
}
482482

483483
@_alwaysEmitIntoClient // Swift 5.7
484-
internal func _copyEncoding(from index: Self) -> Self {
484+
internal func _copyingEncoding(from index: Self) -> Self {
485485
let mask = Self.__utf8Bit | Self.__utf16Bit
486486
return Self((_rawBits & ~mask) | (index._rawBits & mask))
487487
}
488488
}
489489

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-
502490
extension String.Index: Equatable {
503491
@inlinable @inline(__always)
504492
public static func == (lhs: String.Index, rhs: String.Index) -> Bool {

stdlib/public/core/StringObject.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ extension _StringObject {
10091009
}
10101010

10111011
/// Returns whether this string has a UTF-8 storage representation.
1012+
/// If this returns false, then the string is encoded in UTF-16.
10121013
///
10131014
/// This always returns a value corresponding to the string's actual encoding.
10141015
@_alwaysEmitIntoClient
@@ -1030,15 +1031,6 @@ extension _StringObject {
10301031
providesFastUTF8 || _countAndFlags.isForeignUTF8
10311032
}
10321033

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-
10421034
// Get access to fast UTF-8 contents for large strings which provide it.
10431035
@inlinable @inline(__always)
10441036
internal var fastUTF8: UnsafeBufferPointer<UInt8> {

stdlib/public/core/UnicodeHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ extension _StringGuts {
167167
result = idx
168168
} else {
169169
// TODO(String performance): isASCII check
170-
result = scalarAlignSlow(idx)._scalarAligned._copyEncoding(from: idx)
170+
result = scalarAlignSlow(idx)._scalarAligned._copyingEncoding(from: idx)
171171
}
172172

173173
_internalInvariant(isOnUnicodeScalarBoundary(result),

0 commit comments

Comments
 (0)