File tree Expand file tree Collapse file tree 3 files changed +17
-10
lines changed Expand file tree Collapse file tree 3 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -910,23 +910,31 @@ extension _StringGuts {
910
910
_invariantCheck ( )
911
911
}
912
912
913
- @inlinable // @testable
914
- mutating func reserveCapacity( _ capacity: Int ) {
915
- // Small strings can accomodate small capacities
913
+ @inlinable internal
914
+ init ( _initialCapacity capacity: Int ) {
916
915
if capacity <= _SmallUTF8String. capacity {
917
- return
916
+ self . init ( )
917
+ } else {
918
+ let storage = _SwiftStringStorage< UInt8> . create(
919
+ capacity: capacity,
920
+ count: 0 )
921
+ self . init ( _large: storage)
918
922
}
919
- reserveCapacitySlow ( capacity)
920
923
}
921
924
922
- @usableFromInline
923
- mutating func reserveCapacitySlow ( _ capacity: Int ) {
925
+ @usableFromInline // @testable
926
+ mutating func reserveCapacity ( _ capacity: Int ) {
924
927
if _fastPath ( _isUniqueNative ( ) ) {
925
928
if _fastPath ( _object. nativeRawStorage. capacity >= capacity) {
926
929
return
927
930
}
928
931
}
929
932
933
+ // Small strings can accomodate small capacities
934
+ if capacity <= _SmallUTF8String. capacity {
935
+ return
936
+ }
937
+
930
938
let selfCount = self . count
931
939
if isASCII {
932
940
let storage = _copyToNativeStorage (
Original file line number Diff line number Diff line change 63
63
public struct DefaultStringInterpolation : StringInterpolationProtocol {
64
64
/// The string contents accumulated by this instance.
65
65
@usableFromInline
66
- internal var _storage : String = " "
66
+ internal var _storage : String
67
67
68
68
/// Creates a string interpolation with storage pre-sized for a literal
69
69
/// with the indicated attributes.
@@ -75,7 +75,7 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol {
75
75
let capacityPerInterpolation = 2
76
76
let initialCapacity = literalCapacity +
77
77
interpolationCount * capacityPerInterpolation
78
- _storage. reserveCapacity ( initialCapacity)
78
+ _storage = String ( _StringGuts ( _initialCapacity : initialCapacity) )
79
79
}
80
80
81
81
/// Appends a literal segment of a string interpolation.
Original file line number Diff line number Diff line change @@ -125,7 +125,6 @@ extension String {
125
125
/// to allocate.
126
126
///
127
127
/// - Complexity: O(*n*)
128
- @inlinable
129
128
public mutating func reserveCapacity( _ n: Int ) {
130
129
_guts. reserveCapacity ( n)
131
130
}
You can’t perform that action at this time.
0 commit comments