File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -131,20 +131,22 @@ internal struct _CocoaArrayWrapper: RandomAccessCollection {
131
131
subRange bounds: Range < Int > ,
132
132
initializing target: UnsafeMutablePointer < AnyObject >
133
133
) -> UnsafeMutablePointer < AnyObject > {
134
- let nsSubRange = SwiftShims . _SwiftNSRange (
135
- location: bounds. lowerBound,
136
- length: bounds. upperBound - bounds. lowerBound)
137
-
138
- // Copies the references out of the NSArray without retaining them
139
- core. getObjects ( target, range: nsSubRange)
140
-
141
- // Make another pass to retain the copied objects
142
- var result = target
143
- for _ in bounds {
144
- result. initialize ( to: result. pointee)
145
- result += 1
134
+ return withExtendedLifetime ( buffer) {
135
+ let nsSubRange = SwiftShims . _SwiftNSRange (
136
+ location: bounds. lowerBound,
137
+ length: bounds. upperBound - bounds. lowerBound)
138
+
139
+ // Copies the references out of the NSArray without retaining them
140
+ core. getObjects ( target, range: nsSubRange)
141
+
142
+ // Make another pass to retain the copied objects
143
+ var result = target
144
+ for _ in bounds {
145
+ result. initialize ( to: result. pointee)
146
+ result += 1
147
+ }
148
+ return result
146
149
}
147
- return result
148
150
}
149
151
150
152
@_alwaysEmitIntoClient
You can’t perform that action at this time.
0 commit comments