diff --git a/stdlib/public/core/StringGuts.swift b/stdlib/public/core/StringGuts.swift index 7c7a02834db..203feceeee3 100644 --- a/stdlib/public/core/StringGuts.swift +++ b/stdlib/public/core/StringGuts.swift @@ -966,18 +966,22 @@ extension _StringGuts { } } - // TODO (TODO: JIRA): check if we're small and still within capacity + // Small strings can accomodate small capacities + if capacity <= _SmallUTF8String.capacity { + return + } + let selfCount = self.count if isASCII { let storage = _copyToNativeStorage( of: UInt8.self, - from: 0.. \(s.capacity), width = \(s._guts.byteWidth)") + s.reserveCapacity(oldCap + 18) + print("reserving \(oldCap + 18) -> \(s.capacity), width = \(s._guts.byteWidth)") let id1 = s.bufferID - s.insert(contentsOf: repeatElement(x, count: oldCap + 2), at: s.endIndex) - print("extending by \(oldCap + 2) -> \(s.capacity), width = \(s._guts.byteWidth)") + s.insert(contentsOf: repeatElement(x, count: oldCap + 18), at: s.endIndex) + print("extending by \(oldCap + 18) -> \(s.capacity), width = \(s._guts.byteWidth)") expectEqual(id1, s.bufferID) s.insert(contentsOf: repeatElement(x, count: s.capacity + 100), at: s.endIndex) expectNotEqual(id1, s.bufferID)