1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
%{
from gyb_utils import *
}%
${autogenerated_warning()}
% for modifier in visibility_levels:
${visibility_boilerplate(modifier)}
extension UnsafeMutableBufferPointer {
@inlinable
public func initialize(fromContentsOf source: Self) -> Index {
guard source.count > 0 else { return 0 }
precondition(
source.count <= self.count,
"buffer cannot contain every element from source.")
baseAddress.unsafelyUnwrapped.initialize(
from: source.baseAddress.unsafelyUnwrapped,
count: source.count)
return source.count
}
@inlinable
public func initialize(fromContentsOf source: Slice<Self>) -> Index {
let sourceCount = source.count
guard sourceCount > 0 else { return 0 }
precondition(
sourceCount <= self.count,
"buffer cannot contain every element from source.")
baseAddress.unsafelyUnwrapped.initialize(
from: source.base.baseAddress.unsafelyUnwrapped + source.startIndex,
count: sourceCount)
return sourceCount
}
}
extension Slice {
@inlinable @inline(__always)
public func initialize<Element>(
fromContentsOf source: UnsafeMutableBufferPointer<Element>
) -> Index
where Base == UnsafeMutableBufferPointer<Element>
{
let target = UnsafeMutableBufferPointer(rebasing: self)
let i = target.initialize(fromContentsOf: source)
return self.startIndex + i
}
@inlinable @inline(__always)
public func initialize<Element>(
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
) -> Index
where Base == UnsafeMutableBufferPointer<Element>
{
let target = UnsafeMutableBufferPointer(rebasing: self)
let i = target.initialize(fromContentsOf: source)
return self.startIndex + i
}
}
extension UnsafeMutableBufferPointer {
@inlinable @inline(__always)
public func initializeAll<C: Collection>(
fromContentsOf source: C
) where C.Element == Element {
let i = self.initialize(fromContentsOf: source)
assert(i == self.endIndex)
}
@inlinable @inline(__always)
public func initializeAll(fromContentsOf source: Self) {
let i = self.initialize(fromContentsOf: source)
assert(i == self.endIndex)
}
@inlinable @inline(__always)
public func initializeAll(fromContentsOf source: Slice<Self>) {
let i = self.initialize(fromContentsOf: source)
assert(i == self.endIndex)
}
@inlinable @inline(__always)
public func moveInitializeAll(fromContentsOf source: Self) {
let i = self.moveInitialize(fromContentsOf: source)
assert(i == self.endIndex)
}
@inlinable @inline(__always)
public func moveInitializeAll(fromContentsOf source: Slice<Self>) {
let i = self.moveInitialize(fromContentsOf: source)
assert(i == self.endIndex)
}
}
extension Slice {
@inlinable @inline(__always)
public func initializeAll<C: Collection>(
fromContentsOf source: C
) where Base == UnsafeMutableBufferPointer<C.Element> {
let i = self.initialize(fromContentsOf: source)
assert(i == self.endIndex)
}
@inlinable @inline(__always)
public func initializeAll<Element>(
fromContentsOf source: UnsafeMutableBufferPointer<Element>
) where Base == UnsafeMutableBufferPointer<Element> {
let target = UnsafeMutableBufferPointer(rebasing: self)
target.initializeAll(fromContentsOf: source)
}
@inlinable @inline(__always)
public func initializeAll<Element>(
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
) where Base == UnsafeMutableBufferPointer<Element> {
let target = UnsafeMutableBufferPointer(rebasing: self)
target.initializeAll(fromContentsOf: source)
}
@inlinable @inline(__always)
public func moveInitializeAll<Element>(
fromContentsOf source: UnsafeMutableBufferPointer<Element>
) where Base == UnsafeMutableBufferPointer<Element> {
let target = UnsafeMutableBufferPointer(rebasing: self)
target.moveInitializeAll(fromContentsOf: source)
}
@inlinable @inline(__always)
public func moveInitializeAll<Element>(
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
) where Base == UnsafeMutableBufferPointer<Element> {
let target = UnsafeMutableBufferPointer(rebasing: self)
target.moveInitializeAll(fromContentsOf: source)
}
}
% end
${visibility_boilerplate("end")}
|