File tree Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Expand file tree Collapse file tree 1 file changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -818,26 +818,27 @@ extension Unsafe${Mutable}BufferPointer {
818
818
return startIndex. advanced ( by: count)
819
819
}
820
820
821
- guard var position = baseAddress else {
821
+ if self . isEmpty {
822
822
_precondition (
823
823
source. isEmpty,
824
824
" buffer cannot contain every element from source. "
825
825
)
826
826
return startIndex
827
827
}
828
+ _internalInvariant ( _position != nil )
828
829
var iterator = source. makeIterator ( )
829
- for index in indices {
830
- guard let value = iterator. next ( ) else {
831
- return index
830
+ var index = startIndex
831
+ while let value = iterator. next ( ) {
832
+ guard index < endIndex else {
833
+ _preconditionFailure (
834
+ " buffer cannot contain every element from source. "
835
+ )
836
+ break
832
837
}
833
- position . pointee = value
834
- position = position . advanced ( by : 1 )
838
+ _position . _unsafelyUnwrappedUnchecked [ index ] = value
839
+ formIndex ( after : & index )
835
840
}
836
- _precondition (
837
- iterator. next ( ) == nil ,
838
- " buffer cannot contain every element from source. "
839
- )
840
- return endIndex
841
+ return index
841
842
}
842
843
843
844
/// Moves every element of an initialized source buffer into the
You can’t perform that action at this time.
0 commit comments