Skip to content

Commit 1d63710

Browse files
authored
Merge pull request swiftlang#28016 from milseman/swept_under_the_bridge
[stdlib] [gardening] Refactor bridging from StringStorage.swift
2 parents dc668b6 + 8463e53 commit 1d63710

File tree

4 files changed

+360
-354
lines changed

4 files changed

+360
-354
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ set(SWIFTLIB_ESSENTIAL
152152
StringNormalization.swift
153153
StringRangeReplaceableCollection.swift
154154
StringStorage.swift
155+
StringStorageBridge.swift
155156
StringSwitch.swift
156157
StringTesting.swift
157158
StringUnicodeScalarView.swift

stdlib/public/core/StringBridge.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ internal typealias _CocoaString = AnyObject
2323
// Foundation.
2424

2525
@objc private protocol _StringSelectorHolder : _NSCopying {
26-
26+
2727
@objc var length: Int { get }
28-
28+
2929
@objc var hash: UInt { get }
30-
30+
3131
@objc(characterAtIndex:)
3232
func character(at offset: Int) -> UInt16
33-
33+
3434
@objc(getCharacters:range:)
3535
func getCharacters(
3636
_ buffer: UnsafeMutablePointer<UInt16>, range aRange: _SwiftNSRange
3737
)
38-
38+
3939
@objc(_fastCStringContents:)
4040
func _fastCStringContents(
4141
_ requiresNulTermination: Int8
4242
) -> UnsafePointer<CChar>?
43-
43+
4444
@objc(_fastCharacterContents)
4545
func _fastCharacterContents() -> UnsafePointer<UInt16>?
46-
46+
4747
@objc(getBytes:maxLength:usedLength:encoding:options:range:remainingRange:)
4848
func getBytes(_ buffer: UnsafeMutableRawPointer?,
4949
maxLength maxBufferCount: Int,
@@ -52,25 +52,25 @@ internal typealias _CocoaString = AnyObject
5252
options: UInt,
5353
range: _SwiftNSRange,
5454
remaining leftover: UnsafeMutablePointer<_SwiftNSRange>?) -> Int8
55-
55+
5656
@objc(compare:options:range:locale:)
5757
func compare(_ string: _CocoaString,
5858
options: UInt,
5959
range: _SwiftNSRange,
6060
locale: AnyObject?) -> Int
6161

6262
@objc(newTaggedNSStringWithASCIIBytes_:length_:)
63-
func createTaggedString(bytes: UnsafePointer<UInt8>,
63+
func createTaggedString(bytes: UnsafePointer<UInt8>,
6464
count: Int) -> AnyObject?
6565
}
6666

6767
/*
6868
Passing a _CocoaString through _objc() lets you call ObjC methods that the
6969
compiler doesn't know about, via the protocol above. In order to get good
7070
performance, you need a double indirection like this:
71-
71+
7272
func a -> _objc -> func a'
73-
73+
7474
because any refcounting @_effects on 'a' will be lost when _objc breaks ARC's
7575
knowledge that the _CocoaString and _StringSelectorHolder are the same object.
7676
*/
@@ -442,9 +442,9 @@ extension String {
442442
@_effects(releasenone)
443443
public // SPI(Foundation)
444444
func _bridgeToObjectiveCImpl() -> AnyObject {
445-
445+
446446
_connectOrphanedFoundationSubclassesIfNeeded()
447-
447+
448448
// Smol ASCII a) may bridge to tagged pointers, b) can't contain a BOM
449449
if _guts.isSmallASCII {
450450
let maybeTagged = _guts.asSmall.withUTF8 { bufPtr in
@@ -456,7 +456,7 @@ extension String {
456456
}
457457
if let tagged = maybeTagged { return tagged }
458458
}
459-
459+
460460
if _guts.isSmall {
461461
// We can't form a tagged pointer String, so grow to a non-small String,
462462
// and bridge that instead. Also avoids CF deleting any BOM that may be

0 commit comments

Comments
 (0)