Skip to content

Revert "Add an overload of append(contentsOf:) on Array that takes a Collection instead of a Sequence, and try using it to accelerate wCSIA-compatible Sequences" #78243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions stdlib/public/core/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1202,48 +1202,6 @@ extension Array: RangeReplaceableCollection {
_appendElementAssumeUniqueAndCapacity(oldCount, newElement: newElement)
_endMutation()
}

/// Adds the elements of a collection to the end of the array.
///
/// Use this method to append the elements of a collection to the end of this
/// array. This example appends the elements of a `Range<Int>` instance
/// to an array of integers.
///
/// var numbers = [1, 2, 3, 4, 5]
/// numbers.append(contentsOf: 10...15)
/// print(numbers)
/// // Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
///
/// - Parameter newElements: The elements to append to the array.
///
/// - Complexity: O(*m*) on average, where *m* is the length of
/// `newElements`, over many calls to `append(contentsOf:)` on the same
/// array.
@_alwaysEmitIntoClient
@_semantics("array.append_contentsOf")
@_effects(notEscaping self.value**)
public mutating func append(contentsOf newElements: __owned some Collection<Element>) {
let newElementsCount = newElements.count
defer {
_endMutation()
}
_reserveCapacityImpl(minimumCapacity: self.count + newElementsCount,
growForAppend: true)
// This check prevents a data race writing to _swiftEmptyArrayStorage
if newElementsCount == 0 {
return
}

let oldCount = _buffer.mutableCount
let startNewElements = _buffer.mutableFirstElementAddress + oldCount
let buf = UnsafeMutableBufferPointer(
start: startNewElements,
count: newElementsCount)
_debugPrecondition(buf.endIndex <= _buffer.mutableCapacity)
let end = buf.initialize(fromContentsOf: newElements)
_precondition(end == buf.endIndex)
_buffer.mutableCount = _buffer.mutableCount + newElementsCount
}

/// Adds the elements of a sequence to the end of the array.
///
Expand All @@ -1267,14 +1225,6 @@ extension Array: RangeReplaceableCollection {
public mutating func append<S: Sequence>(contentsOf newElements: __owned S)
where S.Element == Element {

let wasContiguous = newElements.withContiguousStorageIfAvailable {
append(contentsOf: $0)
return true
}
if wasContiguous != nil {
return
}

defer {
_endMutation()
}
Expand Down
53 changes: 1 addition & 52 deletions stdlib/public/core/ArraySlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -925,47 +925,6 @@ extension ArraySlice: RangeReplaceableCollection {
_appendElementAssumeUniqueAndCapacity(oldCount, newElement: newElement)
_endMutation()
}

/// Adds the elements of a collection to the end of the array.
///
/// Use this method to append the elements of a collection to the end of this
/// array. This example appends the elements of a `Range<Int>` instance
/// to an array of integers.
///
/// var numbers = [1, 2, 3, 4, 5]
/// numbers.append(contentsOf: 10...15)
/// print(numbers)
/// // Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
///
/// - Parameter newElements: The elements to append to the array.
///
/// - Complexity: O(*m*) on average, where *m* is the length of
/// `newElements`, over many calls to `append(contentsOf:)` on the same
/// array.
@_alwaysEmitIntoClient
@_semantics("array.append_contentsOf")
public mutating func append(contentsOf newElements: __owned some Collection<Element>) {
let newElementsCount = newElements.count
// This check prevents a data race writing to _swiftEmptyArrayStorage
if newElementsCount == 0 {
return
}
defer {
_endMutation()
}
reserveCapacityForAppend(newElementsCount: newElementsCount)
_ = _buffer.beginCOWMutation()

let oldCount = self.count
let startNewElements = _buffer.firstElementAddress + oldCount
let buf = UnsafeMutableBufferPointer(
start: startNewElements,
count: newElementsCount)
_debugPrecondition(buf.endIndex <= self.capacity)
let end = buf.initialize(fromContentsOf: newElements)
_precondition(end == buf.endIndex)
_buffer.count += newElementsCount
}

/// Adds the elements of a sequence to the end of the array.
///
Expand All @@ -988,17 +947,6 @@ extension ArraySlice: RangeReplaceableCollection {
public mutating func append<S: Sequence>(contentsOf newElements: __owned S)
where S.Element == Element {

let wasContiguous = newElements.withContiguousStorageIfAvailable {
append(contentsOf: $0)
return true
}
if wasContiguous != nil {
return
}

defer {
_endMutation()
}
let newElementsCount = newElements.underestimatedCount
reserveCapacityForAppend(newElementsCount: newElementsCount)
_ = _buffer.beginCOWMutation()
Expand Down Expand Up @@ -1027,6 +975,7 @@ extension ArraySlice: RangeReplaceableCollection {
// append them in slow sequence-only mode
_buffer._arrayAppendSequence(IteratorSequence(remainder))
}
_endMutation()
}

@inlinable
Expand Down
51 changes: 0 additions & 51 deletions stdlib/public/core/ContiguousArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -815,49 +815,6 @@ extension ContiguousArray: RangeReplaceableCollection {
_appendElementAssumeUniqueAndCapacity(oldCount, newElement: newElement)
_endMutation()
}

/// Adds the elements of a sequence to the end of the array.
///
/// Use this method to append the elements of a sequence to the end of this
/// array. This example appends the elements of a `Range<Int>` instance
/// to an array of integers.
///
/// var numbers = [1, 2, 3, 4, 5]
/// numbers.append(contentsOf: 10...15)
/// print(numbers)
/// // Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
///
/// - Parameter newElements: The elements to append to the array.
///
/// - Complexity: O(*m*) on average, where *m* is the length of
/// `newElements`, over many calls to `append(contentsOf:)` on the same
/// array.
@_alwaysEmitIntoClient
@_semantics("array.append_contentsOf")
public mutating func append(
contentsOf newElements: __owned some Collection<Element>
) {
let newElementsCount = newElements.count
defer {
_endMutation()
}
_reserveCapacityImpl(minimumCapacity: self.count + newElementsCount,
growForAppend: true)
// This check prevents a data race writing to _swiftEmptyArrayStorage
if newElementsCount == 0 {
return
}

let oldCount = _buffer.mutableCount
let startNewElements = _buffer.mutableFirstElementAddress + oldCount
let buf = UnsafeMutableBufferPointer(
start: startNewElements,
count: newElementsCount)
_debugPrecondition(buf.endIndex <= _buffer.mutableCapacity)
let end = buf.initialize(fromContentsOf: newElements)
_precondition(end == buf.endIndex)
_buffer.count += newElementsCount
}

/// Adds the elements of a sequence to the end of the array.
///
Expand All @@ -879,14 +836,6 @@ extension ContiguousArray: RangeReplaceableCollection {
@_semantics("array.append_contentsOf")
public mutating func append<S: Sequence>(contentsOf newElements: __owned S)
where S.Element == Element {

let wasContiguous = newElements.withContiguousStorageIfAvailable {
append(contentsOf: $0)
return true
}
if wasContiguous != nil {
return
}

defer {
_endMutation()
Expand Down
6 changes: 0 additions & 6 deletions stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1063,12 +1063,6 @@ extension Sequence {
internal func _copySequenceToContiguousArray<
S: Sequence
>(_ source: S) -> ContiguousArray<S.Element> {
let contigArray = source.withContiguousStorageIfAvailable {
_copyCollectionToContiguousArray($0)
}
if let contigArray {
return contigArray
}
let initialCapacity = source.underestimatedCount
var builder =
_UnsafePartiallyInitializedContiguousArrayBuffer<S.Element>(
Expand Down