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

@@ -21,28 +21,28 @@ extension _HashNode {
_ transform: (Element) throws -> T
) rethrows -> _HashNode<Key, T> {
let c = self.count
return try read { source in
return unsafe try read { source in
var result: _HashNode<Key, T>
if isCollisionNode {
result = _HashNode<Key, T>.allocateCollision(
result = unsafe _HashNode<Key, T>.allocateCollision(
count: c, source.collisionHash,
initializingWith: { _ in }
).node
} else {
result = _HashNode<Key, T>.allocate(
result = unsafe _HashNode<Key, T>.allocate(
itemMap: source.itemMap,
childMap: source.childMap,
count: c,
initializingWith: { _, _ in }
).node
}
try result.update { target in
let sourceItems = source.reverseItems
let targetItems = target.reverseItems
unsafe try result.update { target in
let sourceItems = unsafe source.reverseItems
let targetItems = unsafe target.reverseItems
assert(sourceItems.count == targetItems.count)
let sourceChildren = source.children
let targetChildren = target.children
let sourceChildren = unsafe source.children
let targetChildren = unsafe target.children
assert(sourceChildren.count == targetChildren.count)
var i = 0
@@ -52,21 +52,21 @@ extension _HashNode {
defer {
if !success {
targetItems.prefix(i).deinitialize()
targetChildren.prefix(j).deinitialize()
target.clear()
unsafe targetItems.prefix(i).deinitialize()
unsafe targetChildren.prefix(j).deinitialize()
unsafe target.clear()
}
}
while i < targetItems.count {
let key = sourceItems[i].key
let value = try transform(sourceItems[i])
targetItems.initializeElement(at: i, to: (key, value))
let key = unsafe sourceItems[i].key
let value = unsafe try transform(sourceItems[i])
unsafe targetItems.initializeElement(at: i, to: (key, value))
i += 1
}
while j < targetChildren.count {
let child = try sourceChildren[j].mapValues(transform)
targetChildren.initializeElement(at: j, to: child)
let child = unsafe try sourceChildren[j].mapValues(transform)
unsafe targetChildren.initializeElement(at: j, to: child)
j += 1
}
success = true
@@ -81,7 +81,7 @@ extension _HashNode {
copy: Bool = false, extraBytes: Int = 0
) -> _HashNode<Key, Void> {
if Value.self == Void.self {
let node = unsafeBitCast(self, to: _HashNode<Key, Void>.self)
let node = unsafe unsafeBitCast(self, to: _HashNode<Key, Void>.self)
guard copy || !node.hasFreeSpace(extraBytes) else { return node }
return node.copy(withFreeSpace: extraBytes)
}