@@ -676,31 +676,32 @@ extension Unsafe${Mutable}BufferPointer {
676
676
return source. _copyContents ( initializing: self )
677
677
}
678
678
679
- /// Initializes the buffer's memory with the given elements .
679
+ /// Initializes the buffer's memory with every element of the source .
680
680
///
681
- /// Prior to calling the `initialize(fromElements :)` method on a buffer,
682
- /// the memory it references must be uninitialized,
683
- /// or its `Element` type must be a trivial type. After the call,
681
+ /// Prior to calling the `initialize(fromContentsOf :)` method on a buffer,
682
+ /// the memory referenced by the buffer must be uninitialized,
683
+ /// or the `Element` type must be a trivial type. After the call,
684
684
/// the memory referenced by the buffer up to, but not including,
685
685
/// the returned index is initialized.
686
+ /// The buffer must reference enough memory to accommodate
687
+ /// `source.count` elements.
686
688
///
687
689
/// The returned index is the position of the next uninitialized element
688
- /// in the buffer, which is one past the last element written.
689
- /// If `fromElements` contains no elements, the returned index is equal to
690
- /// the buffer's `startIndex`. If `fromElements` contains an equal or greater
691
- /// number of elements than the buffer can hold, the returned index is equal
692
- /// to the buffer's `endIndex`.
690
+ /// in the buffer, one past the index of the last element written.
691
+ /// If `source` contains no elements, the returned index is equal to the
692
+ /// buffer's `startIndex`. If `source` contains as many elements as the buffer
693
+ /// can hold, the returned index is equal to the buffer's `endIndex`.
694
+ ///
695
+ /// - Precondition: `self.count` >= `source.count`
693
696
///
694
- /// - Parameter fromElements : A collection of elements to be used to
697
+ /// - Parameter source : A collection of elements to be used to
695
698
/// initialize the buffer's storage.
696
- /// - Returns: An index to the next uninitialized element in the buffer,
697
- /// or `endIndex`.
698
- @discardableResult
699
+ /// - Returns: An index to the next uninitialized element in the buffer.
699
700
@inlinable
700
701
@_alwaysEmitIntoClient
701
- public func initialize< C : Collection > (
702
- fromElements source: C
703
- ) - > Index where C . Element == Element {
702
+ public func initialize(
703
+ fromContentsOf source: some Collection < Element >
704
+ ) -> Index {
704
705
let count = Swift . min ( self . count, source. count)
705
706
guard count > 0 , let base = baseAddress else { return startIndex }
706
707
@@ -773,21 +774,29 @@ extension Unsafe${Mutable}BufferPointer {
773
774
return ( iterator, endIndex)
774
775
}
775
776
776
- /// Updates the buffer's initialized memory with the given elements .
777
+ /// Updates the buffer's initialized memory with every element of the source .
777
778
///
778
- /// The buffer’s memory must be initialized or its `Element` type
779
- /// must be a trivial type.
779
+ /// Prior to calling the `update(fromContentsOf:)` method on a buffer,
780
+ /// the first `source.count` elements of the buffer's memory must be
781
+ /// initialized, or the buffer's `Element` type must be a trivial type.
782
+ /// The buffer must reference enough initialized memory to accommodate
783
+ /// `source.count` elements.
780
784
///
781
- /// - Parameter fromElements: A collection of elements to be used to update
785
+ /// The returned index is one past the index of the last element updated.
786
+ /// If `source` contains no elements, the returned index is equal to the
787
+ /// buffer's `startIndex`. If `source` contains as many elements as the buffer
788
+ /// can hold, the returned index is equal to the buffer's `endIndex`.
789
+ ///
790
+ /// - Precondition: `self.count` >= `source.count`
791
+ ///
792
+ /// - Parameter source: A collection of elements to be used to update
782
793
/// the buffer's contents.
783
- /// - Returns: An index one past the last updated element in the buffer,
784
- /// or `endIndex`.
785
- @discardableResult
794
+ /// - Returns: An index one past the index of the last element updated.
786
795
@inlinable
787
796
@_alwaysEmitIntoClient
788
- public func update< C : Collection > (
789
- fromElements source: C
790
- ) - > Index where C . Element == Element {
797
+ public func update(
798
+ fromContentsOf source: some Collection < Element >
799
+ ) -> Index {
791
800
let count = Swift . min ( source. count, self . count)
792
801
guard count > 0 , let base = baseAddress else { return startIndex }
793
802
@@ -805,72 +814,98 @@ extension Unsafe${Mutable}BufferPointer {
805
814
}
806
815
807
816
/// Moves every element of an initialized source buffer into the
808
- /// uninitialized memory referenced by this buffer, leaving the
809
- /// source memory uninitialized and this buffer's memory initialized.
817
+ /// uninitialized memory referenced by this buffer, leaving the source memory
818
+ /// uninitialized and this buffer's memory initialized.
819
+ ///
820
+ /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
821
+ /// the memory it references must be uninitialized,
822
+ /// or its `Element` type must be a trivial type. After the call,
823
+ /// the memory referenced by the buffer up to, but not including,
824
+ /// the returned index is initialized. The memory referenced by
825
+ /// `source` is uninitialized after the function returns.
826
+ /// The buffer must reference enough memory to accommodate
827
+ /// `source.count` elements.
828
+ ///
829
+ /// The returned index is the position of the next uninitialized element
830
+ /// in the buffer, one past the index of the last element written.
831
+ /// If `source` contains no elements, the returned index is equal to the
832
+ /// buffer's `startIndex`. If `source` contains as many elements as the buffer
833
+ /// can hold, the returned index is equal to the buffer's `endIndex`.
810
834
///
811
- /// The region of memory starting at the beginning of this buffer and
812
- /// covering `source.count` instances of its `Element` type must be
813
- /// uninitialized, or `Element` must be a trivial type. After calling
814
- /// `moveInitialize(fromElements:)`, the region is initialized and
815
- /// the region of memory underlying `source` is uninitialized.
835
+ /// - Precondition: `self.count` >= `source.count`
816
836
///
817
837
/// - Parameter source: A buffer containing the values to copy. The memory
818
- /// region underlying `source` must be initialized. The memory regions
819
- /// referenced by `source` and this buffer may overlap.
838
+ /// region underlying `source` must be initialized. The memory regions
839
+ /// referenced by `source` and this buffer may overlap.
820
840
/// - Returns: An index to the next uninitialized element in the buffer,
821
- /// or `endIndex`.
822
- @discardableResult
841
+ /// or `endIndex`.
823
842
@inlinable
824
843
@_alwaysEmitIntoClient
825
- public func moveInitialize( fromElements source: Self) - > Index {
844
+ public func moveInitialize( fromContentsOf source: Self) - > Index {
826
845
guard let pointer = source. baseAddress, source. count > 0 else { return 0 }
827
846
_debugPrecondition ( count >= source. count)
828
847
baseAddress. _unsafelyUnwrappedUnchecked. moveInitialize ( from: pointer,
829
848
count: source. count)
830
849
return startIndex. advanced ( by: source. count)
831
850
}
832
851
833
- /// Moves every element of an initialized source buffer slice into the
834
- /// uninitialized memory referenced by this buffer, leaving the
835
- /// source memory uninitialized and this buffer's memory initialized.
852
+ /// Moves every element of an initialized source buffer into the
853
+ /// uninitialized memory referenced by this buffer, leaving the source memory
854
+ /// uninitialized and this buffer's memory initialized.
855
+ ///
856
+ /// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
857
+ /// the memory it references must be uninitialized,
858
+ /// or its `Element` type must be a trivial type. After the call,
859
+ /// the memory referenced by the buffer up to, but not including,
860
+ /// the returned index is initialized. The memory referenced by
861
+ /// `source` is uninitialized after the function returns.
862
+ /// The buffer must reference enough memory to accommodate
863
+ /// `source.count` elements.
864
+ ///
865
+ /// The returned index is the position of the next uninitialized element
866
+ /// in the buffer, one past the index of the last element written.
867
+ /// If `source` contains no elements, the returned index is equal to the
868
+ /// buffer's `startIndex`. If `source` contains as many elements as the buffer
869
+ /// can hold, the returned index is equal to the buffer's `endIndex`.
836
870
///
837
- /// The region of memory starting at the beginning of this buffer and
838
- /// covering `source.count` instances of its `Element` type must be
839
- /// uninitialized, or `Element` must be a trivial type. After calling
840
- /// `moveInitialize(fromElements:)`, the region is initialized and
841
- /// the region of memory underlying `source` is uninitialized.
871
+ /// - Precondition: `self.count` >= `source.count`
842
872
///
843
873
/// - Parameter source: A buffer containing the values to copy. The memory
844
- /// region underlying `source` must be initialized. The memory regions
845
- /// referenced by `source` and this buffer may overlap.
846
- /// - Returns: An index one past the last replaced element in the buffer,
847
- /// or `endIndex`.
848
- @discardableResult
874
+ /// region underlying `source` must be initialized. The memory regions
875
+ /// referenced by `source` and this buffer may overlap.
876
+ /// - Returns: An index to the next uninitialized element in the buffer,
877
+ /// or `endIndex`.
849
878
@inlinable
850
879
@_alwaysEmitIntoClient
851
- public func moveInitialize( fromElements source: Slice < Self > ) -> Index {
852
- return moveInitialize ( fromElements : Self ( rebasing: source) )
880
+ public func moveInitialize( fromContentsOf source: Slice < Self > ) -> Index {
881
+ return moveInitialize ( fromContentsOf : Self ( rebasing: source) )
853
882
}
854
883
855
884
/// Updates this buffer's initialized memory initialized memory by
856
885
/// moving every element from the source buffer,
857
886
/// leaving the source memory uninitialized.
858
887
///
859
- /// The region of memory starting at the beginning of this buffer and
860
- /// covering `fromElements.count` instances of its `Element` type must be
861
- /// initialized, or `Element` must be a trivial type.
862
- /// After calling `moveUpdate(fromElements:)`,
863
- /// the region of memory underlying `source` is uninitialized.
888
+ /// Prior to calling the `moveUpdate(fromContentsOf:)` method on a buffer,
889
+ /// the first `source.count` elements of the buffer's memory must be
890
+ /// initialized, or the buffer's `Element` type must be a trivial type.
891
+ /// The memory referenced by `source` is uninitialized after the function
892
+ /// returns. The buffer must reference enough initialized memory
893
+ /// to accommodate `source.count` elements.
894
+ ///
895
+ /// The returned index is one past the index of the last element updated.
896
+ /// If `source` contains no elements, the returned index is equal to the
897
+ /// buffer's `startIndex`. If `source` contains as many elements as the buffer
898
+ /// can hold, the returned index is equal to the buffer's `endIndex`.
899
+ ///
900
+ /// - Precondition: `self.count` >= `source.count`
864
901
///
865
902
/// - Parameter source: A buffer containing the values to move.
866
- /// The memory region underlying `source` must be initialized. The
867
- /// memory regions referenced by `source` and this pointer must not overlap.
868
- /// - Returns: An index one past the last updated element in the buffer,
869
- /// or `endIndex`.
870
- @discardableResult
903
+ /// The memory region underlying `source` must be initialized. The memory
904
+ /// regions referenced by `source` and this buffer must not overlap.
905
+ /// - Returns: An index one past the index of the last element updated.
871
906
@inlinable
872
907
@_alwaysEmitIntoClient
873
- public func moveUpdate( fromElements source: Self) - > Index {
908
+ public func moveUpdate( fromContentsOf source: Self) - > Index {
874
909
guard let pointer = source. baseAddress, source. count > 0 else { return 0 }
875
910
_debugPrecondition ( count >= source. count)
876
911
baseAddress. _unsafelyUnwrappedUnchecked. moveUpdate ( from: pointer,
@@ -882,22 +917,28 @@ extension Unsafe${Mutable}BufferPointer {
882
917
/// moving every element from the source buffer slice,
883
918
/// leaving the source memory uninitialized.
884
919
///
885
- /// The region of memory starting at the beginning of this buffer and
886
- /// covering `fromElements.count` instances of its `Element` type must be
887
- /// initialized, or `Element` must be a trivial type.
888
- /// After calling `moveUpdate(fromElements:)`,
889
- /// the region of memory underlying `source` is uninitialized.
920
+ /// Prior to calling the `moveUpdate(fromContentsOf:)` method on a buffer,
921
+ /// the first `source.count` elements of the buffer's memory must be
922
+ /// initialized, or the buffer's `Element` type must be a trivial type.
923
+ /// The memory referenced by `source` is uninitialized after the function
924
+ /// returns. The buffer must reference enough initialized memory
925
+ /// to accommodate `source.count` elements.
890
926
///
891
- /// - Parameter source: A buffer containing the values to move.
927
+ /// The returned index is one past the index of the last element updated.
928
+ /// If `source` contains no elements, the returned index is equal to the
929
+ /// buffer's `startIndex`. If `source` contains as many elements as the buffer
930
+ /// can hold, the returned index is equal to the buffer's `endIndex`.
931
+ ///
932
+ /// - Precondition: `self.count` >= `source.count`
933
+ ///
934
+ /// - Parameter source: A buffer slice containing the values to move.
892
935
/// The memory region underlying `source` must be initialized. The
893
936
/// memory regions referenced by `source` and this pointer must not overlap.
894
- /// - Returns: An index one past the last updated element in the buffer,
895
- /// or `endIndex`.
896
- @discardableResult
937
+ /// - Returns: An index one past the index of the last element updated.
897
938
@inlinable
898
939
@_alwaysEmitIntoClient
899
- public func moveUpdate( fromElements source: Slice < Self > ) -> Index {
900
- return moveUpdate ( fromElements : Self ( rebasing: source) )
940
+ public func moveUpdate( fromContentsOf source: Slice < Self > ) -> Index {
941
+ return moveUpdate ( fromContentsOf : Self ( rebasing: source) )
901
942
}
902
943
903
944
/// Deinitializes every instance in this buffer.
0 commit comments