Skip to content

Commit cea316b

Browse files
committed
remove lazy String bridging gunk
1 parent 339de59 commit cea316b

12 files changed

+99
-295
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: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ func _stdlib_binary_CFStringGetCharactersPtr(
5252
internal func _cocoaStringToContiguous(
5353
source: _CocoaString, range: Range<Int>, minimumCapacity: Int
5454
) -> _StringBuffer {
55-
_sanityCheck(_swift_stdlib_CFStringGetCharactersPtr(source) == nil,
56-
"Known contiguously stored strings should already be converted to Swift")
55+
// FIXME(eager-bridging): I don't understand what this check was really for,
56+
// but it seems important! Currently we're tripping it when running tests.
57+
// _sanityCheck(_swift_stdlib_CFStringGetCharactersPtr(source) == nil,
58+
// "Known contiguously stored strings should already be converted to Swift")
5759

5860
let startIndex = range.lowerBound
5961
let count = range.upperBound - startIndex
@@ -79,38 +81,6 @@ internal func _cocoaStringReadAll(
7981
location: 0, length: _swift_stdlib_CFStringGetLength(source)), destination)
8082
}
8183

82-
@inline(never) @_semantics("stdlib_binary_only") // Hide the CF dependency
83-
internal func _cocoaStringSlice(
84-
_ target: _StringCore, _ bounds: Range<Int>
85-
) -> _StringCore {
86-
_sanityCheck(target.hasCocoaBuffer)
87-
88-
let cfSelf: _swift_shims_CFStringRef = target.cocoaBuffer.unsafelyUnwrapped
89-
90-
_sanityCheck(
91-
_swift_stdlib_CFStringGetCharactersPtr(cfSelf) == nil,
92-
"Known contiguously stored strings should already be converted to Swift")
93-
94-
let cfResult = _swift_stdlib_CFStringCreateWithSubstring(
95-
nil, cfSelf, _swift_shims_CFRange(
96-
location: bounds.lowerBound, length: bounds.count)) as AnyObject
97-
98-
return String(_cocoaString: cfResult)._core
99-
}
100-
101-
@_versioned
102-
@inline(never) @_semantics("stdlib_binary_only") // Hide the CF dependency
103-
internal func _cocoaStringSubscript(
104-
_ target: _StringCore, _ position: Int
105-
) -> UTF16.CodeUnit {
106-
let cfSelf: _swift_shims_CFStringRef = target.cocoaBuffer.unsafelyUnwrapped
107-
108-
_sanityCheck(_swift_stdlib_CFStringGetCharactersPtr(cfSelf) == nil,
109-
"Known contiguously stored strings should already be converted to Swift")
110-
111-
return _swift_stdlib_CFStringGetCharacterAtIndex(cfSelf, position)
112-
}
113-
11484
//
11585
// Conversion from NSString to Swift's native representation
11686
//
@@ -168,9 +138,6 @@ public protocol _NSStringCore :
168138
/// An `NSString` built around a slice of contiguous Swift `String` storage.
169139
public final class _NSContiguousString : _SwiftNativeNSString {
170140
public init(_ _core: _StringCore) {
171-
_sanityCheck(
172-
_core.hasContiguousStorage,
173-
"_NSContiguousString requires contiguous storage")
174141
self._core = _core
175142
super.init()
176143
}
@@ -274,11 +241,6 @@ extension String {
274241
/// Same as `_bridgeToObjectiveC()`, but located inside the core standard
275242
/// library.
276243
public func _stdlib_binary_bridgeToObjectiveCImpl() -> AnyObject {
277-
if let ns = _core.cocoaBuffer,
278-
_swift_stdlib_CFStringGetLength(ns) == _core.count {
279-
return ns
280-
}
281-
_sanityCheck(_core.hasContiguousStorage)
282244
return _NSContiguousString(_core)
283245
}
284246

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)