Skip to content

Commit 826dae3

Browse files
committed
[stdlib] Rename stdlib-private init(_ _buffer:) to init(_buffer:)
This is good hygiene, since the buffer will also be a collection and could potentially be passed to the unspecialized Sequence initializer, as indeed was happenining for ArraySlice (see FIXME(ABI) comment).
1 parent a33e608 commit 826dae3

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

stdlib/public/core/ArrayCast.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public func _arrayForceCast<SourceElement, TargetElement>(
5656
if _fastPath(native!.storesOnlyElementsOfType(TargetElement.self)) {
5757
// A native buffer that is known to store only elements of the
5858
// TargetElement can be used directly
59-
return Array(source._buffer.cast(toBufferOf: TargetElement.self))
59+
return Array(_buffer: source._buffer.cast(toBufferOf: TargetElement.self))
6060
}
6161
// Other native buffers must use deferred element type checking
62-
return Array(
62+
return Array(_buffer:
6363
source._buffer.downcast(
6464
toBufferWithDeferredTypeCheckOf: TargetElement.self))
6565
}
@@ -90,7 +90,7 @@ public func _arrayForceCast<SourceElement, TargetElement>(
9090
p += 1
9191
}
9292
}
93-
return Array(_ArrayBuffer(buf, shiftedToStartIndex: 0))
93+
return Array(_buffer: _ArrayBuffer(buf, shiftedToStartIndex: 0))
9494

9595
case (.value, .explicit):
9696
_sanityCheckFailure(
@@ -121,7 +121,7 @@ internal func _arrayConditionalDownCastElements<SourceElement, TargetElement>(
121121

122122
if _fastPath(native != nil) {
123123
if native!.storesOnlyElementsOfType(TargetElement.self) {
124-
return Array(a._buffer.cast(toBufferOf: TargetElement.self))
124+
return Array(_buffer: a._buffer.cast(toBufferOf: TargetElement.self))
125125
}
126126
return nil
127127
}
@@ -136,7 +136,7 @@ internal func _arrayConditionalDownCastElements<SourceElement, TargetElement>(
136136
}
137137
}
138138
}
139-
return Array(a._buffer.cast(toBufferOf: TargetElement.self))
139+
return Array(_buffer: a._buffer.cast(toBufferOf: TargetElement.self))
140140
}
141141
return []
142142
}
@@ -169,7 +169,7 @@ ElementwiseBridging:
169169
p.initialize(with: value!)
170170
p += 1
171171
}
172-
return Array(_ArrayBuffer(buf, shiftedToStartIndex: 0))
172+
return Array(_buffer: _ArrayBuffer(buf, shiftedToStartIndex: 0))
173173
}
174174
while false
175175

stdlib/public/core/Arrays.swift.gyb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ public struct ${Self}<Element>
732732
get {
733733
_checkIndex(bounds.lowerBound)
734734
_checkIndex(bounds.upperBound)
735-
return ArraySlice(_buffer[bounds])
735+
return ArraySlice(_buffer: _buffer[bounds])
736736
}
737737
set(rhs) {
738738
_checkIndex(bounds.lowerBound)
@@ -884,10 +884,19 @@ 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 init(_buffer: _Buffer) {
888888
self._buffer = _buffer
889889
}
890890

891+
%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)
897+
}
898+
%end
899+
891900
public var _buffer: _Buffer
892901
}
893902

@@ -926,7 +935,7 @@ extension ${Self} : ArrayLiteralConvertible {
926935
///
927936
/// - Parameter elements: A variadic list of elements of the new array.
928937
public init(arrayLiteral elements: Element...) {
929-
self.init(_extractOrCopyToNativeArrayBuffer(elements._buffer))
938+
self.init(_buffer: _extractOrCopyToNativeArrayBuffer(elements._buffer))
930939
}
931940
%end
932941
}
@@ -1027,7 +1036,7 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
10271036
public init<S : Sequence>(_ s: S)
10281037
where S.Iterator.Element == Element {
10291038

1030-
self = ${Self}(_Buffer(s._copyToNativeArrayBuffer(),
1039+
self = ${Self}(_buffer: _Buffer(s._copyToNativeArrayBuffer(),
10311040
shiftedToStartIndex: 0))
10321041
}
10331042

@@ -1114,7 +1123,7 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
11141123
storage, to: _ContiguousArrayStorage<Element>.self))
11151124

11161125
return (
1117-
Array(_Buffer(innerBuffer, shiftedToStartIndex: 0)),
1126+
Array(_buffer: _Buffer(innerBuffer, shiftedToStartIndex: 0)),
11181127
innerBuffer.firstElementAddress)
11191128
}
11201129

@@ -2082,7 +2091,7 @@ public func != <Element : Equatable>(
20822091
public func _arrayUpCast<Derived, Base>(_ a: Array<Derived>) -> Array<Base> {
20832092
// FIXME: Dynamic casting is currently not possible without the objc runtime:
20842093
// rdar://problem/18801510
2085-
return Array(a._buffer.cast(toBufferOf: Base.self))
2094+
return Array(_buffer: a._buffer.cast(toBufferOf: Base.self))
20862095
}
20872096
#endif
20882097

@@ -2113,7 +2122,7 @@ extension Array {
21132122
/// * `Element` is bridged verbatim to Objective-C (i.e.,
21142123
/// is a reference type).
21152124
public init(_immutableCocoaArray: _NSArrayCore) {
2116-
self = Array(_ArrayBuffer(nsArray: _immutableCocoaArray))
2125+
self = Array(_buffer: _ArrayBuffer(nsArray: _immutableCocoaArray))
21172126
}
21182127
}
21192128
#endif

0 commit comments

Comments
 (0)