Skip to content

Commit 3288659

Browse files
author
Alexis Beingessner
committed
Remove lazy ObjC representation from String
1 parent e69d4fe commit 3288659

9 files changed

+89
-242
lines changed

stdlib/public/core/Character.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public struct Character :
183183
}
184184
else {
185185
if let native = s._core.nativeBuffer,
186-
native.start == s._core._baseAddress! {
186+
native.start == s._core._baseAddress {
187187
_representation = .large(native._storage)
188188
return
189189
}

stdlib/public/core/String.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ extension String : _ExpressibleByBuiltinUTF16StringLiteral {
399399
baseAddress: UnsafeMutableRawPointer(start),
400400
count: Int(utf16CodeUnitCount),
401401
elementShift: 1,
402-
hasCocoaBuffer: false,
403402
owner: nil))
404403
}
405404
}
@@ -417,7 +416,6 @@ extension String : _ExpressibleByBuiltinStringLiteral {
417416
baseAddress: UnsafeMutableRawPointer(start),
418417
count: Int(utf8CodeUnitCount),
419418
elementShift: 0,
420-
hasCocoaBuffer: false,
421419
owner: nil))
422420
}
423421
else {
@@ -753,7 +751,7 @@ extension String {
753751
}
754752

755753
#if _runtime(_ObjC)
756-
return _cocoaStringToSwiftString_NonASCII(
754+
return String(_cocoaString:
757755
_stdlib_NSStringLowercaseString(self._bridgeToObjectiveCImpl()))
758756
#else
759757
return _nativeUnicodeLowercaseString(self)
@@ -792,7 +790,7 @@ extension String {
792790
}
793791

794792
#if _runtime(_ObjC)
795-
return _cocoaStringToSwiftString_NonASCII(
793+
return String(_cocoaString:
796794
_stdlib_NSStringUppercaseString(self._bridgeToObjectiveCImpl()))
797795
#else
798796
return _nativeUnicodeUppercaseString(self)

stdlib/public/core/StringBridge.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ public class _SwiftNativeNSString {}
7777
/// An `NSString` built around a slice of contiguous Swift `String` storage.
7878
public final class _NSContiguousString : _SwiftNativeNSString, _NSStringCore {
7979
public init(_ _core: _StringCore) {
80-
_sanityCheck(
81-
_core.hasContiguousStorage,
82-
"_NSContiguousString requires contiguous storage")
8380
self._core = _core
8481
super.init()
8582
}
@@ -183,11 +180,6 @@ extension String {
183180
/// Same as `_bridgeToObjectiveC()`, but located inside the core standard
184181
/// library.
185182
public func _stdlib_binary_bridgeToObjectiveCImpl() -> AnyObject {
186-
if let ns = _core.cocoaBuffer,
187-
_swift_stdlib_CFStringGetLength(ns) == _core.count {
188-
return ns
189-
}
190-
_sanityCheck(_core.hasContiguousStorage)
191183
return _NSContiguousString(_core)
192184
}
193185

stdlib/public/core/StringComparable.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
//===----------------------------------------------------------------------===//
23
//
34
// This source file is part of the Swift.org open source project
@@ -73,17 +74,13 @@ extension String {
7374
// Note: this operation should be consistent with equality comparison of
7475
// Character.
7576
#if _runtime(_ObjC)
76-
if self._core.hasContiguousStorage && rhs._core.hasContiguousStorage {
77-
let lhsStr = _NSContiguousString(self._core)
78-
let rhsStr = _NSContiguousString(rhs._core)
79-
let res = lhsStr._unsafeWithNotEscapedSelfPointerPair(rhsStr) {
80-
return Int(
81-
_stdlib_compareNSStringDeterministicUnicodeCollationPointer($0, $1))
82-
}
83-
return res
77+
let lhsStr = _NSContiguousString(self._core)
78+
let rhsStr = _NSContiguousString(rhs._core)
79+
let res = lhsStr._unsafeWithNotEscapedSelfPointerPair(rhsStr) {
80+
return Int(
81+
_stdlib_compareNSStringDeterministicUnicodeCollationPointer($0, $1))
8482
}
85-
return Int(_stdlib_compareNSStringDeterministicUnicodeCollation(
86-
_bridgeToObjectiveCImpl(), rhs._bridgeToObjectiveCImpl()))
83+
return res
8784
#else
8885
switch (_core.isASCII, rhs._core.isASCII) {
8986
case (true, false):

0 commit comments

Comments
 (0)