@@ -69,6 +69,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
69
69
}
70
70
71
71
public required init ( objects: UnsafePointer < AnyObject ? > , count cnt: Int ) {
72
+ _storage. reserveCapacity ( cnt)
72
73
for idx in 0 ..< cnt {
73
74
_storage. append ( objects [ idx] !)
74
75
}
@@ -500,6 +501,10 @@ public class NSMutableArray : NSArray {
500
501
501
502
public init ( capacity numItems: Int ) {
502
503
super. init ( objects: nil , count: 0 )
504
+
505
+ if self . dynamicType === NSMutableArray . self {
506
+ _storage. reserveCapacity ( numItems)
507
+ }
503
508
}
504
509
505
510
public required convenience init ( objects: UnsafePointer < AnyObject ? > , count cnt: Int ) {
@@ -599,6 +604,7 @@ public class NSMutableArray : NSArray {
599
604
public func replaceObjectsInRange( range: NSRange , withObjectsFromArray otherArray: [ AnyObject ] , range otherRange: NSRange ) { NSUnimplemented ( ) }
600
605
public func replaceObjectsInRange( range: NSRange , withObjectsFromArray otherArray: [ AnyObject ] ) {
601
606
if self . dynamicType === NSMutableArray . self {
607
+ _storage. reserveCapacity ( count - range. length + otherArray. count)
602
608
for var idx = 0 ; idx < range. length; idx++ {
603
609
_storage [ idx + range. location] = otherArray [ idx]
604
610
}
@@ -622,6 +628,10 @@ public class NSMutableArray : NSArray {
622
628
public func insertObjects( objects: [ AnyObject ] , atIndexes indexes: NSIndexSet ) {
623
629
precondition ( objects. count == indexes. count)
624
630
631
+ if self . dynamicType === NSMutableArray . self {
632
+ _storage. reserveCapacity ( count + indexes. count)
633
+ }
634
+
625
635
var objectIdx = 0
626
636
indexes. enumerateIndexesUsingBlock ( ) { ( insertionIndex, _) in
627
637
self . insertObject ( objects [ objectIdx++ ] , atIndex: insertionIndex)
0 commit comments