Skip to content

Commit 38efe16

Browse files
authored
Merge pull request #36355 from eeckstein/fix-arrayslice
stdlib: fix ARC for getting an ArraySlice of an CocoaArray with non-contiguous storage.
2 parents a77206c + 375f289 commit 38efe16

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

stdlib/public/core/CocoaArray.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ internal struct _CocoaArrayWrapper: RandomAccessCollection {
8383
let result = _ContiguousArrayBuffer<AnyObject>(
8484
_uninitializedCount: boundsCount,
8585
minimumCapacity: 0)
86-
87-
// Tell Cocoa to copy the objects into our storage
88-
core.getObjects(
89-
UnsafeMutableRawPointer(result.firstElementAddress)
90-
.assumingMemoryBound(to: AnyObject.self),
91-
range: _SwiftNSRange(location: bounds.lowerBound, length: boundsCount))
86+
87+
let base = UnsafeMutableRawPointer(result.firstElementAddress)
88+
.assumingMemoryBound(to: AnyObject.self)
89+
90+
for idx in 0..<boundsCount {
91+
(base + idx).initialize(to: core.objectAt(idx + bounds.lowerBound))
92+
}
9293

9394
return _SliceBuffer(_buffer: result, shiftedToStartIndex: bounds.lowerBound)
9495
}

0 commit comments

Comments
 (0)