Skip to content

Commit 90b3625

Browse files
gribozavrbenlangmuir
authored andcommitted
stdlib: avoid copying the _ContiguousArrayBuffer when initializing an ArraySlice from a literal
1 parent 826dae3 commit 90b3625

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,16 +884,17 @@ public struct ${Self}<Element>
884884

885885
/// Initialization from an existing buffer does not have "array.init"
886886
/// semantics because the caller may retain an alias to buffer.
887-
public init(_buffer: _Buffer) {
887+
public // @testable
888+
init(_buffer: _Buffer) {
888889
self._buffer = _buffer
889890
}
890891

891892
%if Self == 'ArraySlice':
892-
// FIXME(ABI): SR-1873 this shim allows the below init(arrayLiteral:) to
893-
// compile, but it goes through a general collection initializer instead of
894-
// the expected efficient one for _SliceBuffer<Element> above.
895-
public init(_buffer: _ContiguousArrayBuffer<Element>) {
896-
self.init(_buffer)
893+
/// Initialization from an existing buffer does not have "array.init"
894+
/// semantics because the caller may retain an alias to buffer.
895+
public // @testable
896+
init(_buffer: _ContiguousArrayBuffer<Element>) {
897+
self.init(_buffer: _Buffer(_buffer, shiftedToStartIndex: 0))
897898
}
898899
%end
899900

0 commit comments

Comments
 (0)