Sources: Add unsafe keywords where needed

This commit is contained in:
Karoy Lorentey committed 2026-10-01 11:14:29 -07:00
1 parent 13f71ad927
commit d07dc32dfa
301 files changed
+6051 -5498

No files matched your search

@@ -89,7 +89,7 @@ extension UniqueArray where Element: ~Copyable {
moving items: UnsafeMutableBufferPointer<Element>
) -> Range<Int> {
_ensureFreeCapacity(items.count)
return _storage._appendUnchecked(moving: items)
return unsafe _storage._appendUnchecked(moving: items)
}
#if UnstableContainersPreview
@@ -131,8 +131,8 @@ extension UniqueArray where Element: ~Copyable {
moving items: inout OutputSpan<Element>
) -> Range<Int> {
_ensureFreeCapacity(items.count)
return items.withUnsafeMutableBufferPointer { buffer, count in
let source = buffer._extracting(first: count)
return unsafe items.withUnsafeMutableBufferPointer { buffer, count in
let source = unsafe buffer._extracting(first: count)
count = 0
return unsafe _storage._appendUnchecked(moving: source)
}
@@ -159,9 +159,9 @@ extension UniqueArray where Element: ~Copyable {
// FIXME: Remove in favor of the generic RRC algorithm
_ensureFreeCapacity(items.count)
return items.edit { source in
source.withUnsafeMutableBufferPointer { buffer, count in
unsafe source.withUnsafeMutableBufferPointer { buffer, count in
count = 0
return _storage.append(moving: buffer._extracting(first: count))
return unsafe _storage.append(moving: buffer._extracting(first: count))
}
}
}
@@ -184,7 +184,7 @@ extension UniqueArray where Element: ~Copyable {
removing subrange: Range<Int>,
moving newElements: UnsafeMutableBufferPointer<Element>,
) {
replaceSubrange(subrange, moving: newElements)
unsafe replaceSubrange(subrange, moving: newElements)
}
#if UnstableContainersPreview
@@ -258,7 +258,7 @@ extension UniqueArray {
removing subrange: Range<Int>,
copying newElements: UnsafeBufferPointer<Element>
) {
replaceSubrange(subrange, copying: newElements)
unsafe replaceSubrange(subrange, copying: newElements)
}
@available(*, deprecated, renamed: "replace(_:copying:)")
@@ -267,7 +267,7 @@ extension UniqueArray {
removing subrange: Range<Int>,
copying newElements: UnsafeMutableBufferPointer<Element>
) {
self.replaceSubrange(subrange, copying: newElements)
unsafe self.replaceSubrange(subrange, copying: newElements)
}
@available(*, deprecated, renamed: "replace(_:copying:)")
@@ -113,13 +113,14 @@ extension UniqueArray where Element: ~Copyable {
/// - Complexity: O(`self.count` + `items.count`)
@_alwaysEmitIntoClient
@discardableResult
@unsafe
public mutating func insert(
moving items: UnsafeMutableBufferPointer<Element>,
at index: Int
) -> Range<Int> {
// FIXME: Avoid moving the subsequent elements twice.
_ensureFreeCapacity(items.count)
return _storage.insert(moving: items, at: index)
return unsafe _storage.insert(moving: items, at: index)
}
#if UnstableContainersPreview
@@ -231,6 +232,7 @@ extension UniqueArray {
/// - Complexity: O(`self.count` + `newElements.count`)
@inlinable
@discardableResult
@unsafe
public mutating func insert(
copying newElements: UnsafeBufferPointer<Element>, at index: Int
) -> Range<Int> {
@@ -262,6 +264,7 @@ extension UniqueArray {
/// - Complexity: O(`self.count` + `newElements.count`)
@inlinable
@discardableResult
@unsafe
public mutating func insert(
copying newElements: UnsafeMutableBufferPointer<Element>,
at index: Int
@@ -70,7 +70,7 @@ extension UniqueArray where Element: ~Copyable {
precondition(newItemCount >= 0, "Cannot add a negative number of items")
// FIXME: Avoid moving the subsequent elements twice on resize.
_ensureFreeCapacity(newItemCount - subrange.count)
return try _storage._uncheckedReplaceSubrange(
return unsafe try _storage._uncheckedReplaceSubrange(
subrange,
addingCount: newItemCount,
initializingWith: initializer)
@@ -139,7 +139,7 @@ extension UniqueArray where Element: ~Copyable {
_storage._checkValidBounds(subrange)
precondition(newItemCount >= 0, "Cannot add a negative number of items")
_ensureFreeCapacity(newItemCount - subrange.count)
return try _storage._uncheckedReplaceSubrange(
return unsafe try _storage._uncheckedReplaceSubrange(
subrange,
consumingWith: consumer,
addingCount: newItemCount,
@@ -181,13 +181,14 @@ extension UniqueArray where Element: ~Copyable {
/// - Complexity: O(`self.count` + `newElements.count`)
@_alwaysEmitIntoClient
@discardableResult
@unsafe
public mutating func replaceSubrange(
_ subrange: Range<Int>,
moving newElements: UnsafeMutableBufferPointer<Element>,
) -> Range<Int> {
// FIXME: Avoid moving the subsequent elements twice.
_ensureFreeCapacity(newElements.count - subrange.count)
return _storage.replaceSubrange(subrange, moving: newElements)
return unsafe _storage.replaceSubrange(subrange, moving: newElements)
}
#if UnstableContainersPreview
@@ -381,6 +382,7 @@ extension UniqueArray {
@_alwaysEmitIntoClient
@inline(__always)
@discardableResult
@unsafe
public mutating func replaceSubrange(
_ subrange: Range<Int>,
copying newElements: UnsafeBufferPointer<Element>