mirror of
https://github.com/apple/swift-collections
synced 2026-11-26 04:47:48 +00:00
Eliminate some duplicate bounds checks for UniqueArray
This commit is contained in:
2 files changed
+66
-29
No files matched your search
@@ -32,7 +32,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
public mutating func append(_ item: consuming Element) {
|
||||
_ensureFreeCapacity(1)
|
||||
_storage.append(item)
|
||||
unsafe _storage._appendUnchecked(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
moving items: UnsafeMutableBufferPointer<Element>
|
||||
) {
|
||||
_ensureFreeCapacity(items.count)
|
||||
_storage.append(moving: items)
|
||||
_storage._appendUnchecked(moving: items)
|
||||
}
|
||||
|
||||
#if UnstableContainersPreview
|
||||
@@ -129,7 +129,7 @@ extension UniqueArray where Element: ~Copyable {
|
||||
moving items: inout OutputSpan<Element>
|
||||
) {
|
||||
_ensureFreeCapacity(items.count)
|
||||
_storage.append(moving: &items)
|
||||
unsafe _storage._appendUnchecked(moving: &items)
|
||||
}
|
||||
|
||||
#if !UnstableContainersPreview
|
||||
@@ -218,7 +218,7 @@ extension UniqueArray {
|
||||
copying newElements: UnsafeBufferPointer<Element>
|
||||
) {
|
||||
_ensureFreeCapacity(newElements.count)
|
||||
unsafe _storage.append(copying: newElements)
|
||||
unsafe _storage._appendUnchecked(copying: newElements)
|
||||
}
|
||||
|
||||
/// Copies the elements of a buffer to the end of this array.
|
||||
@@ -254,7 +254,7 @@ extension UniqueArray {
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append(copying newElements: Span<Element>) {
|
||||
_ensureFreeCapacity(newElements.count)
|
||||
_storage.append(copying: newElements)
|
||||
unsafe _storage._appendUnchecked(copying: newElements)
|
||||
}
|
||||
|
||||
#if compiler(>=6.4) && UnstableContainersPreview
|
||||
@@ -272,7 +272,7 @@ extension UniqueArray {
|
||||
let span = try it.nextSpan()
|
||||
if span.isEmpty { break }
|
||||
_ensureFreeCapacity(span.count)
|
||||
_storage.append(copying: span)
|
||||
unsafe _storage._appendUnchecked(copying: span)
|
||||
}
|
||||
}
|
||||
// FIXME: Add _append(copyingContainer:), forwarding to the same method on RigidArray
|
||||
@@ -323,7 +323,7 @@ extension UniqueArray {
|
||||
public mutating func append(copying newElements: some Sequence<Element>) {
|
||||
let done: Void? = newElements.withContiguousStorageIfAvailable { buffer in
|
||||
_ensureFreeCapacity(buffer.count)
|
||||
unsafe _storage.append(copying: buffer)
|
||||
unsafe _storage._appendUnchecked(copying: buffer)
|
||||
return
|
||||
}
|
||||
if done != nil { return }
|
||||
@@ -331,8 +331,7 @@ extension UniqueArray {
|
||||
_ensureFreeCapacity(newElements.underestimatedCount)
|
||||
var it = _storage._append(prefixOf: newElements)
|
||||
while let item = it.next() {
|
||||
_ensureFreeCapacity(1)
|
||||
_storage.append(item)
|
||||
self.append(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user