Skip to content

Commit a50260b

Browse files
committed
[stdlib] Avoid unnecessary null-pointer checks in UM[R]BP bulk-copy functions
1 parent b5af518 commit a50260b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,9 @@ extension UnsafeMutableBufferPointer {
946946
$0.count <= self.count,
947947
"buffer cannot contain every element from source."
948948
)
949-
baseAddress?.initialize(from: sourceAddress, count: $0.count)
949+
baseAddress.unsafelyUnwrapped.initialize(
950+
from: sourceAddress, count: $0.count
951+
)
950952
return $0.count
951953
}
952954
if let count {
@@ -1049,7 +1051,7 @@ extension UnsafeMutableBufferPointer {
10491051
$0.count <= self.count,
10501052
"buffer cannot contain every element from source."
10511053
)
1052-
baseAddress?.update(from: sourceAddress, count: $0.count)
1054+
baseAddress.unsafelyUnwrapped.update(from: sourceAddress, count: $0.count)
10531055
return $0.count
10541056
}
10551057
if let count {
@@ -1117,7 +1119,9 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable {
11171119
source.count <= self.count,
11181120
"buffer cannot contain every element from source."
11191121
)
1120-
baseAddress?.moveInitialize(from: sourceAddress, count: source.count)
1122+
baseAddress.unsafelyUnwrapped.moveInitialize(
1123+
from: sourceAddress, count: source.count
1124+
)
11211125
return startIndex.advanced(by: source.count)
11221126
}
11231127
}
@@ -1191,7 +1195,9 @@ extension UnsafeMutableBufferPointer where Element: ~Copyable {
11911195
source.count <= self.count,
11921196
"buffer cannot contain every element from source."
11931197
)
1194-
baseAddress?.moveUpdate(from: sourceAddress, count: source.count)
1198+
baseAddress.unsafelyUnwrapped.moveUpdate(
1199+
from: sourceAddress, count: source.count
1200+
)
11951201
return startIndex.advanced(by: source.count)
11961202
}
11971203
}

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ extension Unsafe${Mutable}RawBufferPointer {
869869
$0.count * MemoryLayout<C.Element>.stride <= self.count,
870870
"buffer cannot contain every element from source collection."
871871
)
872-
let start = baseAddress?.initializeMemory(
872+
let start = baseAddress.unsafelyUnwrapped.initializeMemory(
873873
as: C.Element.self, from: sourceAddress, count: $0.count
874874
)
875875
return .init(start: start, count: $0.count)
@@ -955,7 +955,7 @@ extension Unsafe${Mutable}RawBufferPointer {
955955
source.count * MemoryLayout<T>.stride <= self.count,
956956
"buffer cannot contain every element from source."
957957
)
958-
let initialized = baseAddress?.moveInitializeMemory(
958+
let initialized = baseAddress.unsafelyUnwrapped.moveInitializeMemory(
959959
as: T.self, from: sourceAddress, count: source.count
960960
)
961961
return .init(start: initialized, count: source.count)

0 commit comments

Comments
 (0)