@@ -623,31 +623,28 @@ extension String {
623623
624624 _connectOrphanedFoundationSubclassesIfNeeded ( )
625625
626- // Smol ASCII a) may bridge to tagged pointers, b) can't contain a BOM
627- if _guts. isSmallASCII {
628- let maybeTagged = _guts . asSmall . withUTF8 { bufPtr in
629- return unsafe _createCFString(
626+ if _guts . isSmall {
627+ return unsafe _guts. asSmall . withUTF8 { bufPtr in
628+ // Smol ASCII a) may bridge to tagged pointers, b) can't contain a BOM
629+ if _guts . isSmallASCII , let result = unsafe _createCFString(
630630 bufPtr. baseAddress. _unsafelyUnwrappedUnchecked,
631631 bufPtr. count,
632632 kCFStringEncodingUTF8
633- )
634- }
635- if let tagged = maybeTagged { return tagged }
636- }
637-
638- if _guts. isSmall {
639- // We can't form a tagged pointer String, so grow to a non-small String,
633+ ) {
634+ return result
635+ }
636+ // We can't form a tagged pointer String, so make a non-small String,
640637 // and bridge that instead. Also avoids CF deleting any BOM that may be
641638 // present
642- var copy = self
643- // TODO: small capacity minimum is lifted, just need to make native
644- copy . _guts . grow ( _SmallString . capacity + 1 )
645- _internalInvariant ( !copy . _guts. isSmall )
646- return copy . _bridgeToObjectiveCImpl ( )
639+ return unsafe __StringStorage . create (
640+ initializingFrom : bufPtr ,
641+ codeUnitCapacity : bufPtr . count ,
642+ isASCII : _guts. isSmallASCII )
643+ }
647644 }
648645 if _guts. _object. isImmortal && !_guts. _object. largeFastIsConstantCocoa {
649646 if _guts. isASCII && _guts. _object. isFastZeroTerminated {
650- let ptr = unsafe _guts. _object . fastUTF8 . baseAddress!
647+ let ptr = unsafe _guts. _object . fastUTF8 . baseAddress . _unsafelyUnwrappedUnchecked
651648 let count = _guts. count
652649 if let indirect = unsafe _stdlib_binary_createIndirectTaggedPointerNSString(
653650 ptr: ptr, count: count
0 commit comments