Skip to content

Commit 6ac6dc9

Browse files
committed
Reimplement NSArray.getObjects
1 parent b7372f2 commit 6ac6dc9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Foundation/NSArray.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,15 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
177177
/// - Experiment: This is a draft API currently under consideration for official import into Foundation
178178
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
179179
public func getObjects(inout objects: [AnyObject], range: NSRange) {
180+
objects.reserveCapacity(objects.count + range.length)
181+
180182
if self.dynamicType === NSArray.self || self.dynamicType === NSMutableArray.self {
181-
if range.location == 0 && range.length == count {
182-
objects = _storage
183-
return
184-
}
183+
objects.insertContentsOf(_storage[range.toRange()!], at: 0)
184+
return
185185
}
186+
186187
for idx in 0..<range.length {
187-
objects[idx] = self[range.location + idx]
188+
objects.insert(self[range.location + idx], atIndex: idx)
188189
}
189190
}
190191

0 commit comments

Comments
 (0)