Skip to content

Commit 9eea282

Browse files
committed
Switch range operators ".." and "...".
- 1..3 now means 1,2 - 1...3 now means 1,2,3 Implements <rdar://problem/16839891> Swift SVN r18066
1 parent 2fe6987 commit 9eea282

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+216
-211
lines changed

stdlib/core/Algorithm.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func _quickSort<C: MutableCollection where C.IndexType: SignedInteger>(
145145

146146
// Partition and sort.
147147
let part_idx : C.IndexType = partition(&elements, range, &less)
148-
_quickSort(&elements, range.startIndex...part_idx, &less);
149-
_quickSort(&elements, part_idx...range.endIndex, &less);
148+
_quickSort(&elements, range.startIndex..part_idx, &less);
149+
_quickSort(&elements, part_idx..range.endIndex, &less);
150150
}
151151

152152
struct Less<T: Comparable> {
@@ -156,15 +156,15 @@ struct Less<T: Comparable> {
156156
}
157157

158158
func sort<T>(var array: T[], pred: (T, T) -> Bool) -> T[] {
159-
quickSort(&array, 0...array.count, pred)
159+
quickSort(&array, 0..array.count, pred)
160160
return array
161161
}
162162

163163
/// The functions below are a copy of the functions above except that
164164
/// they don't accept a predicate and they are hardcoded to use the less-than
165165
/// comparator.
166166
func sort<T : Comparable>(var array: T[]) -> T[] {
167-
quickSort(&array, 0...array.count)
167+
quickSort(&array, 0..array.count)
168168
return array
169169
}
170170

@@ -254,8 +254,8 @@ func _quickSort<C: MutableCollection where C.GeneratorType.Element: Comparable,
254254
}
255255
// Partition and sort.
256256
let part_idx : C.IndexType = partition(&elements, range)
257-
_quickSort(&elements, range.startIndex...part_idx);
258-
_quickSort(&elements, part_idx...range.endIndex);
257+
_quickSort(&elements, range.startIndex..part_idx);
258+
_quickSort(&elements, part_idx..range.endIndex);
259259
}
260260
//// End of non-predicate sort functions.
261261

@@ -320,7 +320,7 @@ func split<Seq: Sliceable, R:LogicValue>(
320320
if isSeparator(seq[j]) {
321321
if startIndex {
322322
var i = startIndex!
323-
result.append(seq[i...j])
323+
result.append(seq[i..j])
324324
startIndex = .Some(j.succ())
325325
if ++splits >= maxSplit {
326326
break
@@ -339,7 +339,7 @@ func split<Seq: Sliceable, R:LogicValue>(
339339

340340
switch startIndex {
341341
case .Some(var i):
342-
result.append(seq[i...seq.endIndex])
342+
result.append(seq[i..seq.endIndex])
343343
default:
344344
()
345345
}

stdlib/core/Arrays.swift.gyb

+9-9
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ extension ${Self} : ArrayType {
100100
buffer = Buffer()
101101
reserve(count)
102102
var p = buffer.elementStorage
103-
for _ in 0...count {
103+
for _ in 0..count {
104104
p++.initialize(value)
105105
}
106106
buffer.count = count
@@ -156,7 +156,7 @@ extension ${Self} : ArrayType {
156156
mutating func reserve(newCapacity: Int) {
157157
if !buffer.requestUniqueMutableBuffer(newCapacity) {
158158
var newBuffer = NativeArrayBuffer<T>(count: count, minimumCapacity: newCapacity)
159-
buffer._uninitializedCopy(0...count, target: newBuffer.elementStorage)
159+
buffer._uninitializedCopy(0..count, target: newBuffer.elementStorage)
160160
buffer = Buffer(newBuffer)
161161
}
162162
assert(capacity >= newCapacity)
@@ -173,21 +173,21 @@ extension ${Self} : ArrayType {
173173
assert(count > 0, "can't pop from an empty ${Self}")
174174
let c = count
175175
let result = self[c - 1]
176-
replace(&self, (c - 1)...c, EmptyCollection())
176+
replace(&self, (c - 1)..c, EmptyCollection())
177177
return result
178178
}
179179

180180
/// Insert an element at the given index in O(N). Requires: atIndex
181181
/// <= count
182182
mutating func insert(atIndex: Int, newElement: T) {
183-
replace(&self, atIndex...atIndex, CollectionOfOne(newElement))
183+
replace(&self, atIndex..atIndex, CollectionOfOne(newElement))
184184
}
185185

186186
/// Remove the element at the given index. Worst case complexity:
187187
/// O(N). Requires: index < count
188188
mutating func removeAt(index: Int) -> T {
189189
let result = self[index]
190-
replace(&self, index...(index + 1), EmptyCollection())
190+
replace(&self, index..(index + 1), EmptyCollection())
191191
return result
192192
}
193193

@@ -221,7 +221,7 @@ extension ${Self} : ArrayType {
221221
let count = self.count
222222
result.reserve(count)
223223
var p = result.buffer.elementStorage
224-
for i in 0...count {
224+
for i in 0..count {
225225
p++.initialize( transform(self[i]) )
226226
}
227227
result.buffer.count = count
@@ -356,7 +356,7 @@ func replace<
356356
elements[j] = newValues[i++]
357357
}
358358
// Initialize the hole left by sliding the tail forward
359-
for j in oldTailIndex...newTailIndex {
359+
for j in oldTailIndex..newTailIndex {
360360
(elements + j).initialize(newValues[i++])
361361
}
362362
}
@@ -535,9 +535,9 @@ func _arrayOutOfPlaceUpdate<
535535
backing.count = 0
536536
}
537537
else {
538-
let newStart = source._uninitializedCopy(0...headCount, target: destStart)
538+
let newStart = source._uninitializedCopy(0..headCount, target: destStart)
539539
initializeNewElements.call(newStart)
540-
source._uninitializedCopy(headCount + oldCount...sourceCount,
540+
source._uninitializedCopy(headCount + oldCount..sourceCount,
541541
target: newEnd)
542542
}
543543
source = Buffer(dest!)

stdlib/core/Collection.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ protocol MutableSliceable : Sliceable, MutableCollection {
180180
}
181181

182182
func dropFirst<Seq : Sliceable>(seq: Seq) -> Seq.SliceType {
183-
return seq[seq.startIndex.succ()...seq.endIndex]
183+
return seq[seq.startIndex.succ()..seq.endIndex]
184184
}
185185

186186
func dropLast<
187187
Seq: Sliceable
188188
where Seq.IndexType: BidirectionalIndex
189189
>(seq: Seq) -> Seq.SliceType {
190-
return seq[seq.startIndex...seq.endIndex.pred()]
190+
return seq[seq.startIndex..seq.endIndex.pred()]
191191
}

stdlib/core/Dictionary.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ class _NativeDictionaryStorageOwnerBase
665665
nativeStorage: nativeStorage, offset: Int(theState.extra.0))
666666
let endIndex = nativeStorage.endIndex
667667
var stored = 0
668-
for i in 0...count {
668+
for i in 0..count {
669669
if (currIndex == endIndex) {
670670
break
671671
}
@@ -803,7 +803,7 @@ enum _VariantDictionaryStorage<KeyType : Hashable, ValueType> :
803803
let newNativeStorage = newNativeOwner.nativeStorage
804804
let newCapacity = newNativeStorage.capacity
805805

806-
for i in 0...oldCapacity {
806+
for i in 0..oldCapacity {
807807
var x = oldNativeStorage[i]
808808
if x {
809809
if oldCapacity == newCapacity {

stdlib/core/NSSwiftArray.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class NSSwiftArray : HeapBufferStorageBase, CocoaArray {
5757
count: range.length)
5858
}
5959

60-
for i in range.location...range.location + range.length {
60+
for i in range.location..range.location + range.length {
6161
dst++.initialize(reinterpretCast(buffer[i]))
6262
}
6363
}

stdlib/core/OutputStream.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func _adHocPrint<T, TargetStream : OutputStream>(
6666
if mirror is _TupleMirror {
6767
print("(", &target)
6868
var first = true
69-
for i in 0...mirror.count {
69+
for i in 0..mirror.count {
7070
if first {
7171
first = false
7272
} else {

stdlib/core/Process.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct _Process {
1717
// FIXME: Use a by-index-initializing constructor of Array here when we
1818
// have that, so we don't need this awkward closure initialization.
1919
var _args = new String[Int(C_ARGC)]
20-
for i in 0...Int(C_ARGC) {
20+
for i in 0..Int(C_ARGC) {
2121
_args[i] = String.fromCString(C_ARGV[i])
2222
}
2323
return _args

stdlib/core/Range.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ func count<I: RandomAccessIndex>(r: Range<I>) -> I.DistanceType {
124124

125125
/// \brief Any model of ForwardIndex can be turned into a Range with min...max
126126
@transparent
127-
func ... <Pos : ForwardIndex> (min: Pos, max: Pos) -> Range<Pos> {
127+
func .. <Pos : ForwardIndex> (min: Pos, max: Pos) -> Range<Pos> {
128128
return Range(start: min, end: max)
129129
}
130130

131131
@transparent
132-
func .. <Pos : ForwardIndex> (min: Pos, max: Pos) -> Range<Pos> {
132+
func ... <Pos : ForwardIndex> (min: Pos, max: Pos) -> Range<Pos> {
133133
return Range(start: min, end: max.succ())
134134
}
135135

stdlib/core/Reflection.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func _dumpWithMirror<TargetStream : OutputStream>(
230230
if maxItemCounter <= 0 { return }
231231
--maxItemCounter
232232

233-
for _ in 0...indent { print(" ") }
233+
for _ in 0..indent { print(" ") }
234234

235235
let count = mirror.count
236236
let bullet = count == 0 ? "-"
@@ -256,9 +256,9 @@ func _dumpWithMirror<TargetStream : OutputStream>(
256256

257257
if maxDepth <= 0 { return }
258258

259-
for i in 0...count {
259+
for i in 0..count {
260260
if maxItemCounter <= 0 {
261-
for _ in 0...(indent+4) { print(" ") }
261+
for _ in 0..(indent+4) { print(" ") }
262262
let remainder = count - i
263263
print("(\(remainder)", &targetStream)
264264
if i > 0 { print(" more", &targetStream) }

stdlib/core/String.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,6 @@ func == (lhs: _Nil, rhs: String) -> Bool { return false }
290290
extension String : Sliceable {
291291
subscript(subRange: Range<Index>) -> String {
292292
return String(
293-
unicodeScalars[subRange.startIndex._base...subRange.endIndex._base]._base)
293+
unicodeScalars[subRange.startIndex._base..subRange.endIndex._base]._base)
294294
}
295295
}

stdlib/core/StringCore.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ struct _StringCore {
298298
}
299299
else if (hasCocoaBuffer) {
300300
_StringCore(
301-
_cocoaStringToContiguous(source: cocoaBuffer!, range: 0...count,
301+
_cocoaStringToContiguous(source: cocoaBuffer!, range: 0..count,
302302
minimumCapacity: 0)
303303
).encode(encoding, output: output)
304304
}

stdlib/core/StringLegacy.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension String {
3131
self = String(_StringBuffer(capacity: s.core.count * sz,
3232
initialSize: 0,
3333
elementWidth: s.core.elementWidth))
34-
for i in 0...sz {
34+
for i in 0..sz {
3535
self += s
3636
}
3737
}
@@ -86,15 +86,15 @@ extension String {
8686
while i != end {
8787
let u8 = utf8[i++]
8888
if u8 < 0x80 {
89-
if 97...123 ~= u8 {
89+
if 97..123 ~= u8 {
9090
resultArray[j++] = u8 - 32
9191
} else {
9292
resultArray[j++] = u8
9393
}
9494
} else if u8 < 0xE0 {
9595
resultArray[j++] = u8
9696
let u8_1 = utf8[i++]
97-
if u8 == 0xC3 && 0xA0...0xBF ~= Int(u8_1) && u8_1 != 0xB7 {
97+
if u8 == 0xC3 && 0xA0..0xBF ~= Int(u8_1) && u8_1 != 0xB7 {
9898
resultArray[j++] = u8_1 - 0x20
9999
} else {
100100
resultArray[j++] = u8_1
@@ -122,15 +122,15 @@ extension String {
122122
while i != end {
123123
let u8 = utf8[i++]
124124
if u8 < 0x80 {
125-
if 65...91 ~= u8 {
125+
if 65..91 ~= u8 {
126126
resultArray[j++] = u8 + 32
127127
} else {
128128
resultArray[j++] = u8
129129
}
130130
} else if u8 < 0xE0 {
131131
resultArray[j++] = u8
132132
let u8_1 = utf8[i++]
133-
if u8 == 0xC3 && 0x80...0x9F ~= u8_1 && u8_1 != 0x97 {
133+
if u8 == 0xC3 && 0x80..0x9F ~= u8_1 && u8_1 != 0x97 {
134134
resultArray[j++] = u8_1 + 0x20
135135
} else {
136136
resultArray[j++] = u8_1
@@ -311,7 +311,7 @@ extension String {
311311
// Since Int.min has a larger absolute value, perform addition with
312312
// negative numbers; detect underflows before they happen.
313313
var res : Int = 0
314-
for c in scalars[start...scalars.endIndex] {
314+
for c in scalars[start..scalars.endIndex] {
315315
if !c.isDigit() {
316316
// Conversion failed if a non-digit is encountered.
317317
return .None
@@ -347,10 +347,10 @@ extension String {
347347
func substr(start: Int) -> String {
348348
var rng = unicodeScalars
349349
var startIndex = rng.startIndex
350-
for i in 0...start {
350+
for i in 0..start {
351351
++startIndex
352352
}
353-
return rng[startIndex...rng.endIndex]
353+
return rng[startIndex..rng.endIndex]
354354
}
355355

356356
/// \brief Split the given string at the given delimiter character, returning
@@ -362,7 +362,7 @@ extension String {
362362
var rng = unicodeScalars
363363
for i in indices(rng) {
364364
if rng[i] == delim {
365-
return (rng[rng.startIndex...i], rng[i.succ()...rng.endIndex], true)
365+
return (rng[rng.startIndex..i], rng[i.succ()..rng.endIndex], true)
366366
}
367367
}
368368
return (self, "", false)
@@ -378,7 +378,7 @@ extension String {
378378
var rng = unicodeScalars
379379
for i in indices(rng) {
380380
if pred(rng[i]) {
381-
return (rng[rng.startIndex...i], rng[i], rng[i.succ()...rng.endIndex], true)
381+
return (rng[rng.startIndex..i], rng[i], rng[i.succ()..rng.endIndex], true)
382382
}
383383
}
384384
return (self, "🎃", String(), false)

stdlib/core/StringUnicodeScalarView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ struct UnicodeScalarView : Sliceable, Sequence {
7272
}
7373

7474
func __slice__(start: IndexType, end: IndexType) -> UnicodeScalarView {
75-
return UnicodeScalarView(_base[start._position...end._position])
75+
return UnicodeScalarView(_base[start._position..end._position])
7676
}
7777

7878
subscript(r: Range<IndexType>) -> UnicodeScalarView {
79-
return UnicodeScalarView(_base[r.startIndex._position...r.endIndex._position])
79+
return UnicodeScalarView(_base[r.startIndex._position..r.endIndex._position])
8080
}
8181

8282
struct GeneratorType : Generator {

stdlib/core/Unicode.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ extension UTF16 {
249249
size: UInt(count) * UInt(Builtin.strideof(U.self)))
250250
}
251251
else {
252-
for i in 0...count {
252+
for i in 0..count {
253253
let u16 = T.toUTF16CodeUnit((source + i).get())
254254
(destination + i).set(U.fromUTF16CodeUnit(u16))
255255
}

stdlib/core/UnsafePointer.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct UnsafePointer<T> : BidirectionalIndex, Comparable, Hashable {
121121
assert(
122122
source > self || source < self - count,
123123
"moveAssignFrom non-following overlapping range")
124-
for i in 0...count {
124+
for i in 0..count {
125125
self[i] = (source + i).move()
126126
}
127127
}
@@ -132,7 +132,7 @@ struct UnsafePointer<T> : BidirectionalIndex, Comparable, Hashable {
132132
assert(
133133
source >= self || source < self - count,
134134
"moveInitializeFrom non-following overlapping range; use moveInitializeBackwardFrom")
135-
for i in 0...count {
135+
for i in 0..count {
136136
(self + i).initialize((source + i).move())
137137
}
138138
}
@@ -142,7 +142,7 @@ struct UnsafePointer<T> : BidirectionalIndex, Comparable, Hashable {
142142
assert(
143143
source >= self || source < self - count,
144144
"initializeFrom non-following overlapping range")
145-
for i in 0...count {
145+
for i in 0..count {
146146
(self + i).initialize(source[i])
147147
}
148148
}

0 commit comments

Comments
 (0)