mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Restore Array value semantics
'nuff said. Swift SVN r18923
This commit is contained in:
@@ -42,10 +42,25 @@ struct ${Self}<T> : MutableCollection, Sliceable {
|
||||
_precondition(index >= 0, "Negative ${Self} index is out of range")
|
||||
return _buffer[index]
|
||||
}
|
||||
nonmutating set {
|
||||
set {
|
||||
_precondition(index < count, "${Self} index out of range")
|
||||
_precondition(index >= 0, "Negative array index is out of range")
|
||||
_buffer[index] = newValue
|
||||
if _buffer.isMutableAndUniquelyReferenced() {
|
||||
_buffer[index] = newValue
|
||||
}
|
||||
else {
|
||||
{
|
||||
(inout buffer: _Buffer, e: Element)->() in
|
||||
var newBuffer = ContiguousArrayBuffer<T>(
|
||||
count: buffer.count, minimumCapacity: buffer.count)
|
||||
let target = buffer._uninitializedCopy(
|
||||
0..index, target: newBuffer.elementStorage)
|
||||
target.initialize(e)
|
||||
buffer._uninitializedCopy(
|
||||
(index + 1)..buffer.count, target: target + 1)
|
||||
buffer = _Buffer(newBuffer)
|
||||
}(&_buffer, newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,15 +162,12 @@ extension ${Self} : ArrayType {
|
||||
/// array.
|
||||
/// Complexity: O(N)
|
||||
func copy() -> ${Self} {
|
||||
var result = self
|
||||
result.reserveCapacity(0)
|
||||
return result
|
||||
return self
|
||||
}
|
||||
|
||||
/// Ensure the uniqueness of the array.
|
||||
/// Complexity: O(N)
|
||||
mutating func unshare() {
|
||||
reserveCapacity(0)
|
||||
func unshare() {
|
||||
}
|
||||
|
||||
/// Ensure the array has enough mutable contiguous storage to store
|
||||
|
||||
Reference in New Issue
Block a user