Skip to content

Commit dc0be0e

Browse files
authored
Merge pull request #14060 from milseman/vacuous_singleton
[string] Workaround fail emptySingleton check.
2 parents b1e37b9 + 9a87d24 commit dc0be0e

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)