Skip to content

Commit 339de59

Browse files
committed
make String bridging eager
1 parent af5cdc0 commit 339de59

File tree

2 files changed

+3
-42
lines changed

2 files changed

+3
-42
lines changed

stdlib/public/core/ObjCMirrors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func _getObjCChild<T>(_: Int, _: _MagicMirrorData) -> (T, _Mirror)
2020

2121
func _getObjCSummary(_ data: _MagicMirrorData) -> String {
2222
let theDescription = _swift_stdlib_objcDebugDescription(data._loadValue(ofType: AnyObject.self)) as AnyObject
23-
return _cocoaStringToSwiftString_NonASCII(theDescription)
23+
return String(_cocoaString: theDescription)
2424
}
2525

2626
public // SPI(runtime)

stdlib/public/core/StringBridge.swift

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@ func _stdlib_binary_CFStringGetCharactersPtr(
4343
return UnsafeMutablePointer(mutating: _swift_stdlib_CFStringGetCharactersPtr(source))
4444
}
4545

46-
/// Bridges `source` to `Swift.String`, assuming that `source` has non-ASCII
47-
/// characters (does not apply ASCII optimizations).
48-
@inline(never) @_semantics("stdlib_binary_only") // Hide the CF dependency
49-
func _cocoaStringToSwiftString_NonASCII(
50-
_ source: _CocoaString
51-
) -> String {
52-
let cfImmutableValue = _stdlib_binary_CFStringCreateCopy(source)
53-
let length = _stdlib_binary_CFStringGetLength(cfImmutableValue)
54-
let start = _stdlib_binary_CFStringGetCharactersPtr(cfImmutableValue)
55-
56-
return String(_StringCore(
57-
baseAddress: start,
58-
count: length,
59-
elementShift: 1,
60-
hasCocoaBuffer: true,
61-
owner: unsafeBitCast(cfImmutableValue, to: Optional<AnyObject>.self)))
62-
}
63-
6446
/// Loading Foundation initializes these function variables
6547
/// with useful values
6648

@@ -154,30 +136,9 @@ extension String {
154136

155137
let length = _swift_stdlib_CFStringGetLength(cfImmutableValue)
156138

157-
// Look first for null-terminated ASCII
158-
// Note: the code in clownfish appears to guarantee
159-
// nul-termination, but I'm waiting for an answer from Chris Kane
160-
// about whether we can count on it for all time or not.
161-
let nulTerminatedASCII = _swift_stdlib_CFStringGetCStringPtr(
162-
cfImmutableValue, kCFStringEncodingASCII)
163-
164-
// start will hold the base pointer of contiguous storage, if it
165-
// is found.
166-
var start: UnsafeMutableRawPointer?
167-
let isUTF16 = (nulTerminatedASCII == nil)
168-
if isUTF16 {
169-
let utf16Buf = _swift_stdlib_CFStringGetCharactersPtr(cfImmutableValue)
170-
start = UnsafeMutableRawPointer(mutating: utf16Buf)
171-
} else {
172-
start = UnsafeMutableRawPointer(mutating: nulTerminatedASCII)
173-
}
174-
175139
self._core = _StringCore(
176-
baseAddress: start,
177-
count: length,
178-
elementShift: isUTF16 ? 1 : 0,
179-
hasCocoaBuffer: true,
180-
owner: cfImmutableValue)
140+
_cocoaStringToContiguous(
141+
source: cfImmutableValue, range: 0..<length, minimumCapacity: 0))
181142
}
182143
}
183144

0 commit comments

Comments
 (0)