mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
ArraySlice indexes no longer zero-based
ArraySlice indices now map directly onto the collection it is slicing and maintains that mapping even after mutations. Before: var a = Array(0..<10) var s = a[5..<10] s.indices // 0..<5 s[0] = 111 s // [111, 6, 7, 8, 9] s.removeFirst() s.indices // 1..<5 After: var a = Array(0..<10) var s = a[5..<10] s.indices // 5..<10 s[5] = 99 s // [99, 6, 7, 8, 9] s.removeFirst() s.indices // 6..<10 - Refactor some of the internals of the buffer types to make it easier to read and understand. - Add Array, ArraySlice, and ContiguousArray to the test suite at the RangeReplaceable test entry points, subjecting them to the same tests as all of our collections. - Update existing test expectations for the indexing changes. rdar://problem/21866825 Swift SVN r30840
This commit is contained in:
@@ -86,7 +86,7 @@ public func _arrayForceCast<SourceElement, TargetElement>(
|
||||
p++.initialize(unsafeBitCast(bridged!, TargetElement.self))
|
||||
}
|
||||
}
|
||||
return Array(_ArrayBuffer(buf))
|
||||
return Array(_ArrayBuffer(buf, shiftedToStartIndex: 0))
|
||||
|
||||
case (.Value, .Explicit):
|
||||
_sanityCheckFailure(
|
||||
@@ -152,7 +152,7 @@ internal func _arrayConditionalBridgeElements<SourceElement, TargetElement>(
|
||||
let buf = _ContiguousArrayBuffer<TargetElement>(
|
||||
count: source.count, minimumCapacity: 0)
|
||||
|
||||
var p = buf.baseAddress
|
||||
var p = buf.firstElementAddress
|
||||
|
||||
ElementwiseBridging:
|
||||
repeat {
|
||||
@@ -164,12 +164,12 @@ ElementwiseBridging:
|
||||
}
|
||||
p++.initialize(value!)
|
||||
}
|
||||
return Array(_ArrayBuffer(buf))
|
||||
return Array(_ArrayBuffer(buf, shiftedToStartIndex: 0))
|
||||
}
|
||||
while false
|
||||
|
||||
// Don't destroy anything we never created.
|
||||
buf.count = p - buf.baseAddress
|
||||
buf.count = p - buf.firstElementAddress
|
||||
|
||||
// Report failure
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user