mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Bridge non-ASCII SmallStrings as native Swift Strings rather than by creating CFStrings. This gets consistent behavior with non-smol Strings when the String contains a BOM
This commit is contained in:
@@ -321,15 +321,25 @@ extension String {
|
||||
@_effects(releasenone)
|
||||
public // SPI(Foundation)
|
||||
func _bridgeToObjectiveCImpl() -> AnyObject {
|
||||
if _guts.isSmall {
|
||||
// Smol ASCII a) may bridge to tagged pointers, b) can't contain a BOM
|
||||
if _guts.isSmallASCII {
|
||||
return _guts.asSmall.withUTF8 { bufPtr in
|
||||
return _createCFString(
|
||||
bufPtr.baseAddress._unsafelyUnwrappedUnchecked,
|
||||
bufPtr.count,
|
||||
kCFStringEncodingUTF8
|
||||
bufPtr.baseAddress._unsafelyUnwrappedUnchecked,
|
||||
bufPtr.count,
|
||||
kCFStringEncodingUTF8
|
||||
)
|
||||
}
|
||||
}
|
||||
if _guts.isSmall {
|
||||
// We can't form a tagged pointer String, so grow to a non-small String,
|
||||
// and bridge that instead. Also avoids CF deleting any BOM that may be
|
||||
// present
|
||||
var copy = self
|
||||
copy._guts.grow(_SmallString.capacity + 1)
|
||||
_internalInvariant(!copy._guts.isSmall)
|
||||
return copy._bridgeToObjectiveCImpl()
|
||||
}
|
||||
if _guts._object.isImmortal {
|
||||
// TODO: We'd rather emit a valid ObjC object statically than create a
|
||||
// shared string class instance.
|
||||
|
||||
Reference in New Issue
Block a user