Skip to content

Commit 1255e10

Browse files
committed
[stdlib] [gardening] Remove whitespace, document growth issue
1 parent e50096f commit 1255e10

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

stdlib/public/core/StringGutsRangeReplaceable.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension _StringGuts {
5858
internal init(_initialCapacity capacity: Int) {
5959
self.init()
6060
if _slowPath(capacity > _SmallString.capacity) {
61-
self.grow(capacity)
61+
self.grow(capacity) // TODO: no factor should be applied
6262
}
6363
}
6464

@@ -68,7 +68,7 @@ extension _StringGuts {
6868
if let currentCap = self.uniqueNativeCapacity, currentCap >= n { return }
6969

7070
// Grow
71-
self.grow(n)
71+
self.grow(n) // TODO: no factor should be applied
7272
}
7373

7474
// Grow to accomodate at least `n` code units
@@ -128,11 +128,11 @@ extension _StringGuts {
128128
} else {
129129
sufficientCapacity = false
130130
}
131-
131+
132132
if self.isUniqueNative && sufficientCapacity {
133133
return
134134
}
135-
135+
136136
// If we have to resize anyway, and we fit in smol, we should have made one
137137
_internalInvariant(totalCount > _SmallString.capacity)
138138

@@ -145,7 +145,7 @@ extension _StringGuts {
145145
growthTarget = Swift.max(
146146
totalCount, _growArrayCapacity(nativeCapacity ?? 0))
147147
}
148-
self.grow(growthTarget)
148+
self.grow(growthTarget) // NOTE: this already has exponential growth...
149149
}
150150

151151
internal mutating func append(_ other: _StringGuts) {
@@ -157,7 +157,7 @@ extension _StringGuts {
157157
}
158158
append(_StringGutsSlice(other))
159159
}
160-
160+
161161
@inline(never)
162162
@_effects(readonly)
163163
private func _foreignConvertedToSmall() -> _SmallString {
@@ -170,7 +170,7 @@ extension _StringGuts {
170170
_internalInvariant(smol._guts.isSmall)
171171
return smol._guts.asSmall
172172
}
173-
173+
174174
private func _convertedToSmall() -> _SmallString {
175175
_internalInvariant(utf8Count <= _SmallString.capacity)
176176
if _fastPath(isSmall) {
@@ -186,25 +186,25 @@ extension _StringGuts {
186186
defer { self._invariantCheck() }
187187

188188
let otherCount = slicedOther.utf8Count
189-
189+
190190
let totalCount = utf8Count + otherCount
191-
191+
192192
/*
193193
Goal: determine if we need to allocate new native capacity
194194
Possible scenarios in which we need to allocate:
195195
• Not uniquely owned and native: we can't use the capacity to grow into,
196196
have to become unique + native by allocating
197197
• Not enough capacity: have to allocate to grow
198-
198+
199199
Special case: a non-smol String that can fit in a smol String but doesn't
200200
meet the above criteria shouldn't throw away its buffer just to be smol.
201201
The reasoning here is that it may be bridged or have reserveCapacity'd
202202
in preparation for appending more later, in which case we would end up
203203
have to allocate anyway to convert back from smol.
204-
204+
205205
If we would have to re-allocate anyway then that's not a problem and we
206206
should just be smol.
207-
207+
208208
e.g. consider
209209
var str = "" // smol
210210
str.reserveCapacity(100) // large native unique
@@ -215,15 +215,15 @@ extension _StringGuts {
215215
nativeUnusedCapacity! >= otherCount
216216
let shouldBeSmol = totalCount <= _SmallString.capacity &&
217217
(isSmall || !hasEnoughUsableSpace)
218-
218+
219219
if shouldBeSmol {
220220
let smolSelf = _convertedToSmall()
221221
let smolOther = String(Substring(slicedOther))._guts._convertedToSmall()
222222
// TODO: In-register slicing
223223
self = _StringGuts(_SmallString(smolSelf, appending: smolOther)!)
224224
return
225225
}
226-
226+
227227
prepareForAppendInPlace(totalCount: totalCount, otherUTF8Count: otherCount)
228228

229229
if slicedOther.isFastUTF8 {

0 commit comments

Comments
 (0)