Skip to content

Commit 99fcb2d

Browse files
committed
Change all uses of x = x.successor() to use x._successorInPlace()
...because it is apparently more efficient in some cases. Technically we don't do this in ALL places, because it would be unfortunate if the implementation of _successorInPlace() were self recursive :-)
1 parent 0bfacde commit 99fcb2d

9 files changed

+22
-22
lines changed

stdlib/public/core/ArrayBufferType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ extension _ArrayBufferType {
160160
var i = newValues.startIndex
161161
for j in subRange {
162162
elements[j] = newValues[i]
163-
i = i.successor()
163+
i._successorInPlace()
164164
}
165165
// Initialize the hole left by sliding the tail forward
166166
for j in oldTailIndex..<newTailIndex {
167167
(elements + j).initialize(newValues[i])
168-
i = i.successor()
168+
i._successorInPlace()
169169
}
170170
_expectEnd(i, newValues)
171171
}
@@ -175,8 +175,8 @@ extension _ArrayBufferType {
175175
var j = newValues.startIndex
176176
for _ in 0..<newCount {
177177
elements[i] = newValues[j]
178-
i = i.successor()
179-
j = j.successor()
178+
i._successorInPlace()
179+
j._successorInPlace()
180180
}
181181
_expectEnd(j, newValues)
182182

stdlib/public/core/Collection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ internal func _writeBackMutableSlice<
728728
newElementIndex != newElementsEndIndex {
729729

730730
self_[selfElementIndex] = slice[newElementIndex]
731-
selfElementIndex = selfElementIndex.successor()
732-
newElementIndex = newElementIndex.successor()
731+
selfElementIndex._successorInPlace()
732+
newElementIndex._successorInPlace()
733733
}
734734

735735
_precondition(

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ internal func _copyCollectionToNativeArrayBuffer<
609609
for _ in 0..<count {
610610
// FIXME(performance): use _initializeTo().
611611
p.initialize(source[i])
612-
i = i.successor()
613-
p = p.successor()
612+
i._successorInPlace()
613+
p._successorInPlace()
614614
}
615615
_expectEnd(i, source)
616616
return result

stdlib/public/core/Existential.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal struct _CollectionOf<
4444
return AnyGenerator {
4545
() -> T? in
4646
if _fastPath(index != self.endIndex) {
47-
index = index.successor()
47+
index._successorInPlace()
4848
return self._subscriptImpl(index)
4949
}
5050
return nil

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ public func == <Key : Equatable, Value : Equatable>(
12311231

12321232
let endIndex = lhsNative.endIndex
12331233
for var index = lhsNative.startIndex; index != endIndex;
1234-
index = index.successor() {
1234+
index._successorInPlace() {
12351235
let (key, value) = lhsNative.assertingGet(index)
12361236
let optRhsValue: AnyObject? =
12371237
rhsCocoa.maybeGet(_bridgeToObjectiveCUnconditional(key))
@@ -2390,7 +2390,7 @@ final internal class _Native${Self}StorageKeyNSEnumerator<
23902390
return nil
23912391
}
23922392
let bridgedKey: AnyObject = nativeStorageOwner._getBridgedKey(nextIndex)
2393-
nextIndex = nextIndex.successor()
2393+
nextIndex._successorInPlace()
23942394
return bridgedKey
23952395
}
23962396

@@ -2415,7 +2415,7 @@ final internal class _Native${Self}StorageKeyNSEnumerator<
24152415
// Return only a single element so that code can start iterating via fast
24162416
// enumeration, terminate it, and continue via NSEnumerator.
24172417
let bridgedKey: AnyObject = nativeStorageOwner._getBridgedKey(nextIndex)
2418-
nextIndex = nextIndex.successor()
2418+
nextIndex._successorInPlace()
24192419

24202420
let unmanagedObjects = _UnmanagedAnyObjectArray(objects)
24212421
unmanagedObjects[0] = bridgedKey
@@ -2767,7 +2767,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
27672767
let bridgedKey: AnyObject = _getBridgedKey(currIndex)
27682768
unmanagedObjects[i] = bridgedKey
27692769
++stored
2770-
currIndex = currIndex.successor()
2770+
currIndex._successorInPlace()
27712771
}
27722772
theState.extra.0 = CUnsignedLong(currIndex.offset)
27732773
state.memory = theState
@@ -3970,7 +3970,7 @@ internal struct ${Self}MirrorPosition<${TypeParametersDecl}> {
39703970

39713971
internal mutating func successor() {
39723972
_intPos = _intPos + 1
3973-
${Self}Pos = ${Self}Pos.successor()
3973+
${Self}Pos._successorInPlace()
39743974
}
39753975

39763976
}

stdlib/public/core/Index.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ extension ForwardIndexType {
216216
var p = self
217217
var i : Distance = 0
218218
while i != n {
219-
p = p.successor()
219+
p._successorInPlace()
220220
i = i + 1
221221
}
222222
return p
@@ -232,7 +232,7 @@ extension ForwardIndexType {
232232
var i : Distance = 0
233233
while i != n {
234234
if p == limit { break }
235-
p = p.successor()
235+
p._successorInPlace()
236236
i = i + 1
237237
}
238238
return p
@@ -254,7 +254,7 @@ extension ForwardIndexType {
254254
var count: Distance = 0
255255
while p != end {
256256
count += 1
257-
p = p.successor()
257+
p._successorInPlace()
258258
}
259259
return count
260260
}

stdlib/public/core/Sort.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func _insertionSort<
5656

5757
// One element is trivially already-sorted, thus pre-increment
5858
// Continue until the sorted elements cover the whole sequence
59-
sortedEnd = sortedEnd.successor()
59+
sortedEnd._successorInPlace()
6060
while sortedEnd != range.endIndex {
6161
// get the first unsorted element
6262
let x: C.Generator.Element = elements[sortedEnd]
@@ -81,7 +81,7 @@ func _insertionSort<
8181
// Plop x into position
8282
elements[i] = x
8383
}
84-
sortedEnd = sortedEnd.successor()
84+
sortedEnd._successorInPlace()
8585
}
8686
}
8787
}

stdlib/public/core/StringCharacterView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ extension String.CharacterView : CollectionType {
143143

144144
var gcb0 = graphemeClusterBreakProperty.getPropertyRawValue(
145145
unicodeScalars[start].value)
146-
start = start.successor()
146+
start._successorInPlace()
147147

148-
for ; start != end; start = start.successor() {
148+
for ; start != end; start._successorInPlace() {
149149
// FIXME(performance): consider removing this "fast path". A branch
150150
// that is hard to predict could be worse for performance than a few
151151
// loads from cache to fetch the property 'gcb1'.

stdlib/public/core/StringLegacy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ extension String {
158158
let rng = unicodeScalars
159159
var startIndex = rng.startIndex
160160
for _ in 0..<start {
161-
startIndex = startIndex.successor()
161+
startIndex._successorInPlace()
162162
}
163163
return String(rng[startIndex..<rng.endIndex])
164164
}

0 commit comments

Comments
 (0)