Skip to content

Commit 9571d46

Browse files
authored
Merge pull request swiftlang#25131 from stephentyrone/de-gyb-fixedarray
2 parents e434bdb + 9573841 commit 9571d46

File tree

4 files changed

+19
-120
lines changed

4 files changed

+19
-120
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(SWIFTLIB_ESSENTIAL
6262
Equatable.swift
6363
ErrorType.swift
6464
Filter.swift
65+
FixedArray.swift
6566
FlatMap.swift
6667
Flatten.swift
6768
FloatingPoint.swift
@@ -126,7 +127,6 @@ set(SWIFTLIB_ESSENTIAL
126127
ShadowProtocols.swift
127128
Shims.swift
128129
Slice.swift
129-
SmallBuffer.swift
130130
SmallString.swift
131131
Sort.swift
132132
StaticString.swift
@@ -185,7 +185,6 @@ set(SWIFTLIB_ESSENTIAL
185185
set(SWIFTLIB_ESSENTIAL_GYB_SOURCES
186186
AtomicInt.swift.gyb
187187
Codable.swift.gyb
188-
FixedArray.swift.gyb
189188
FloatingPointParsing.swift.gyb
190189
FloatingPointTypes.swift.gyb
191190
IntegerTypes.swift.gyb

stdlib/public/core/FixedArray.swift.gyb renamed to stdlib/public/core/FixedArray.swift

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,26 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
%{
18-
# The sizes to generate code for.
19-
sizes = [2, 4, 8, 16]
20-
}%
21-
22-
% for N in sizes:
23-
24-
internal struct _FixedArray${N}<T> {
17+
internal struct _FixedArray16<T> {
2518
// ABI TODO: This makes assumptions about tuple layout in the ABI, namely that
2619
// they are laid out contiguously and individually addressable (i.e. strided).
2720
//
2821
internal var storage: (
29-
// A ${N}-wide tuple of type T
30-
% for i in range(0, N-1):
31-
T,
32-
% end
33-
T
22+
// A 16-wide tuple of type T
23+
T, T, T, T, T, T, T, T,
24+
T, T, T, T, T, T, T, T
3425
)
3526

3627
var _count: Int8
3728
}
3829

39-
extension _FixedArray${N} {
30+
extension _FixedArray16 {
4031
internal static var capacity: Int {
41-
@inline(__always) get { return ${N} }
32+
@inline(__always) get { return 16 }
4233
}
4334

4435
internal var capacity: Int {
45-
@inline(__always) get { return ${N} }
36+
@inline(__always) get { return 16 }
4637
}
4738

4839
internal var count: Int {
@@ -51,7 +42,7 @@ extension _FixedArray${N} {
5142
}
5243
}
5344

54-
extension _FixedArray${N} : RandomAccessCollection, MutableCollection {
45+
extension _FixedArray16 : RandomAccessCollection, MutableCollection {
5546
internal typealias Index = Int
5647

5748
internal var startIndex : Index {
@@ -70,7 +61,7 @@ extension _FixedArray${N} : RandomAccessCollection, MutableCollection {
7061
let res: T = withUnsafeBytes(of: storage) {
7162
(rawPtr : UnsafeRawBufferPointer) -> T in
7263
let stride = MemoryLayout<T>.stride
73-
_internalInvariant(rawPtr.count == ${N}*stride, "layout mismatch?")
64+
_internalInvariant(rawPtr.count == 16*stride, "layout mismatch?")
7465
let bufPtr = UnsafeBufferPointer(
7566
start: rawPtr.baseAddress!.assumingMemoryBound(to: T.self),
7667
count: count)
@@ -98,23 +89,21 @@ extension _FixedArray${N} : RandomAccessCollection, MutableCollection {
9889
}
9990
}
10091

101-
extension _FixedArray${N} {
92+
extension _FixedArray16 {
10293
internal mutating func append(_ newElement: T) {
10394
_internalInvariant(count < capacity)
10495
_count += 1
10596
self[count-1] = newElement
10697
}
10798
}
10899

109-
extension _FixedArray${N} where T : ExpressibleByIntegerLiteral {
100+
extension _FixedArray16 where T : ExpressibleByIntegerLiteral {
110101
@inline(__always)
111102
internal init(count: Int) {
112-
_internalInvariant(count >= 0 && count <= _FixedArray${N}.capacity)
103+
_internalInvariant(count >= 0 && count <= _FixedArray16.capacity)
113104
self.storage = (
114-
% for i in range(0, N-1):
115-
0,
116-
% end
117-
0
105+
0, 0, 0, 0, 0, 0, 0, 0,
106+
0, 0, 0, 0, 0, 0, 0, 0
118107
)
119108
self._count = Int8(truncatingIfNeeded: count)
120109
}
@@ -126,17 +115,17 @@ extension _FixedArray${N} where T : ExpressibleByIntegerLiteral {
126115

127116
@inline(__always)
128117
internal init(allZeros: ()) {
129-
self.init(count: ${N})
118+
self.init(count: 16)
130119
}
131120
}
132121

133-
extension _FixedArray${N} {
122+
extension _FixedArray16 {
134123
internal mutating func withUnsafeMutableBufferPointer<R>(
135124
_ body: (UnsafeMutableBufferPointer<Element>) throws -> R
136125
) rethrows -> R {
137126
let count = self.count // for exclusive access
138127
return try withUnsafeMutableBytes(of: &storage) { rawBuffer in
139-
_internalInvariant(rawBuffer.count == ${N}*MemoryLayout<T>.stride,
128+
_internalInvariant(rawBuffer.count == 16*MemoryLayout<T>.stride,
140129
"layout mismatch?")
141130
let buffer = UnsafeMutableBufferPointer<Element>(
142131
start: rawBuffer.baseAddress._unsafelyUnwrappedUnchecked
@@ -151,7 +140,7 @@ extension _FixedArray${N} {
151140
) rethrows -> R {
152141
let count = self.count // for exclusive access
153142
return try withUnsafeBytes(of: &storage) { rawBuffer in
154-
_internalInvariant(rawBuffer.count == ${N}*MemoryLayout<T>.stride,
143+
_internalInvariant(rawBuffer.count == 16*MemoryLayout<T>.stride,
155144
"layout mismatch?")
156145
let buffer = UnsafeBufferPointer<Element>(
157146
start: rawBuffer.baseAddress._unsafelyUnwrappedUnchecked
@@ -161,9 +150,3 @@ extension _FixedArray${N} {
161150
}
162151
}
163152
}
164-
165-
% end
166-
167-
// ${'Local Variables'}:
168-
// eval: (read-only-mode 1)
169-
// End:

stdlib/public/core/GroupInfo.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
"VarArgs.swift",
145145
"CTypes.swift",
146146
"MemoryLayout.swift",
147-
"SmallBuffer.swift"
148147
],
149148
"KeyPaths": [
150149
"KeyPath.swift"

stdlib/public/core/SmallBuffer.swift

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)