Skip to content

Commit 99505d0

Browse files
committed
[stdlib] simplify update(from:)
- one fewer variable, one fewer return point - thanks @benrimmington
1 parent aabf2e2 commit 99505d0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,15 @@ extension Unsafe${Mutable}BufferPointer {
769769
from source: S
770770
) -> (unwritten: S.Iterator, index: Index) where S.Element == Element {
771771
var iterator = source.makeIterator()
772-
guard var pointer = baseAddress else { return (iterator, startIndex) }
773-
for index in indices {
774-
guard let element = iterator.next() else {
775-
return (iterator, index)
776-
}
777-
pointer.pointee = element
778-
pointer += 1
772+
guard !self.isEmpty else { return (iterator, startIndex) }
773+
_internalInvariant(_position != nil)
774+
var index = startIndex
775+
while index < endIndex {
776+
guard let element = iterator.next() else { break }
777+
_position._unsafelyUnwrappedUnchecked[index] = element
778+
formIndex(after: &index)
779779
}
780-
return (iterator, endIndex)
780+
return (iterator, index)
781781
}
782782

783783
/// Updates the buffer's initialized memory with every element of the source.

0 commit comments

Comments
 (0)