[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.
This commit is contained in:
Michael Ilseman
2018-01-22 11:07:52 -08:00
parent d14b8abc8b
commit 9a87d24bc7
2 changed files with 8 additions and 19 deletions

View File

@@ -1006,10 +1006,16 @@ extension _StringGuts {
@_inlineable
public // TODO(StringGuts): for testing only
mutating func append(_ other: _StringGuts) {
if _isEmptySingleton {
// FIXME(TODO: JIRA): shouldn't _isEmptySingleton be sufficient?
if _isEmptySingleton || self.count == 0 && !_object.isNative {
// We must be careful not to discard any capacity that
// may have been reserved for the append -- this is why
// we check for the empty string singleton rather than
// a zero `count` above.
self = other
return
}
defer { _fixLifetime(other) }
if _slowPath(other._isOpaque) {
self.append(other._asOpaque())