Skip to content

Commit 9a87d24

Browse files
committed
[string] Workaround fail emptySingleton check.
This is a temporary workaround for some situations where the empty singleton is not being formed correctly (and this seems to be highly configuration dependent). Work around that for now for also checking for empty non-storage-backed Strings. This is probably too expensive a check for us to do long-term, but it works for now.
1 parent d14b8ab commit 9a87d24

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

stdlib/public/core/String.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,24 +1011,7 @@ extension String {
10111011
/// - Parameter other: Another string.
10121012
@_inlineable // FIXME(sil-serialize-all)
10131013
public mutating func append(_ other: String) {
1014-
if self._guts._isEmptySingleton {
1015-
// We must be careful not to discard any capacity that
1016-
// may have been reserved for the append -- this is why
1017-
// we check for the empty string singleton rather than
1018-
// a zero `count` above.
1019-
self = other
1020-
return
1021-
}
1022-
defer { _fixLifetime(other) }
1023-
if _slowPath(other._guts._isOpaque) {
1024-
self._guts.append(other._guts._asOpaque())
1025-
return
1026-
}
1027-
if other._guts.isASCII {
1028-
self._guts.append(other._guts._unmanagedASCIIView)
1029-
return
1030-
}
1031-
self._guts.append(other._guts._unmanagedUTF16View)
1014+
self._guts.append(other._guts)
10321015
}
10331016

10341017
/// Appends the given Unicode scalar to the string.

stdlib/public/core/StringGuts.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,16 @@ extension _StringGuts {
10061006
@_inlineable
10071007
public // TODO(StringGuts): for testing only
10081008
mutating func append(_ other: _StringGuts) {
1009-
if _isEmptySingleton {
1009+
// FIXME(TODO: JIRA): shouldn't _isEmptySingleton be sufficient?
1010+
if _isEmptySingleton || self.count == 0 && !_object.isNative {
1011+
// We must be careful not to discard any capacity that
1012+
// may have been reserved for the append -- this is why
1013+
// we check for the empty string singleton rather than
1014+
// a zero `count` above.
10101015
self = other
10111016
return
10121017
}
1018+
10131019
defer { _fixLifetime(other) }
10141020
if _slowPath(other._isOpaque) {
10151021
self.append(other._asOpaque())

0 commit comments

Comments
 (0)