Skip to content

Commit d6a8845

Browse files
authored
Merge pull request #68614 from kubamracek/embedded-arrays
[embedded] Avoid use of a metatype in array implementation for embedded Swift
2 parents ad9f316 + 65d706d commit d6a8845

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

stdlib/public/core/ArrayShared.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ func _allocateUninitializedArray<Element>(_ builtinCount: Builtin.Word)
4141
if count > 0 {
4242
// Doing the actual buffer allocation outside of the array.uninitialized
4343
// semantics function enables stack propagation of the buffer.
44+
let storageType: _ContiguousArrayStorage<Element>.Type
45+
#if !$Embedded
46+
storageType = getContiguousArrayStorageType(for: Element.self)
47+
#else
48+
storageType = _ContiguousArrayStorage<Element>.self
49+
#endif
4450
let bufferObject = Builtin.allocWithTailElems_1(
45-
getContiguousArrayStorageType(for: Element.self),
46-
builtinCount, Element.self)
51+
storageType, builtinCount, Element.self)
4752

4853
let (array, ptr) = Array<Element>._adoptStorage(bufferObject, count: count)
4954
return (array, ptr._rawValue)

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,14 @@ internal struct _ContiguousArrayBuffer<Element>: _ArrayBufferProtocol {
297297
self = _ContiguousArrayBuffer<Element>()
298298
}
299299
else {
300+
let storageType: _ContiguousArrayStorage<Element>.Type
301+
#if !$Embedded
302+
storageType = getContiguousArrayStorageType(for: Element.self)
303+
#else
304+
storageType = _ContiguousArrayStorage<Element>.self
305+
#endif
300306
_storage = Builtin.allocWithTailElems_1(
301-
getContiguousArrayStorageType(for: Element.self),
302-
realMinimumCapacity._builtinWordValue, Element.self)
307+
storageType, realMinimumCapacity._builtinWordValue, Element.self)
303308

304309
let storageAddr = UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(_storage))
305310
let allocSize: Int?

0 commit comments

Comments
 (0)