From 5d01ca428c20a16a063eb178cd789769cbd37566 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Jun 2011 23:34:58 -0400 Subject: [PATCH] Optimise CPArrayController insertObject:atArrangedObjectIndex: by not attempting to arrange the content array. The given index is only meant for the arrangedObjects. --- AppKit/CPArrayController.j | 8 ++++++-- Tests/AppKit/CPArrayControllerTest.j | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AppKit/CPArrayController.j b/AppKit/CPArrayController.j index 42ad4acc3..2f72ad429 100644 --- a/AppKit/CPArrayController.j +++ b/AppKit/CPArrayController.j @@ -771,7 +771,8 @@ } /*! - Adds an object at a given index to the receiver's collection. + Adds an object at a given index in the receiver's arrangedObjects. Also add the object + to the content collection (although at the end rather than the given index). @param id anObject - The object to add to the collection. @param int anIndex - The index to insert the object at. @@ -790,7 +791,10 @@ See _disableSetContent explanation in addObject:. */ _disableSetContent = YES; - [_contentObject insertObject:anObject atIndex:anIndex]; + // The atArrangedObjectIndex: part of this method's name only refers to where the + // object goes in arrangedObjects, not in the content array. So use addObject:, + // not insertObject:atIndex: here for speed. + [_contentObject addObject:anObject]; _disableSetContent = NO; if (_clearsFilterPredicateOnInsertion) diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index 992852b9f..aa76c3f5c 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -80,6 +80,7 @@ [arrayController insertObject:object atArrangedObjectIndex:1]; [self assert:object equals:[[arrayController arrangedObjects] objectAtIndex:1]]; + [self assertTrue:[[arrayController content] containsObject:object] message:@"object should be inserted into content"]; } - (void)testAddObjectUpdatesArrangedObjectsWithoutSortDescriptors