Re-added the root children count optimization in the results outline.

This commit is contained in:
Virgil Dupras 2010-02-12 11:34:00 +01:00
parent a4bf1c8be6
commit 514426b980
5 changed files with 26 additions and 0 deletions

View File

@ -19,4 +19,5 @@ http://www.hardcoded.net/licenses/hs_license
- (BOOL)renameSelected:(NSString *)aNewName;
- (void)sortBy:(NSInteger)aIdentifier ascending:(BOOL)aAscending;
- (void)markSelected;
- (NSArray *)rootChildrenCounts;
@end

View File

@ -13,6 +13,7 @@ http://www.hardcoded.net/licenses/hs_license
@interface ResultOutline : HSOutline
{
NSIndexSet *_deltaColumns;
NSArray *_rootChildrenCounts;
}
- (PyResultTree *)py;
- (BOOL)powerMarkerMode;

View File

@ -15,6 +15,7 @@ http://www.hardcoded.net/licenses/hs_license
- (id)initWithPyParent:(id)aPyParent view:(HSOutlineView *)aOutlineView
{
self = [super initWithPyClassName:@"PyResultOutline" pyParent:aPyParent view:aOutlineView];
_rootChildrenCounts = nil;
return self;
}
@ -62,6 +63,19 @@ http://www.hardcoded.net/licenses/hs_license
}
/* Datasource */
- (NSInteger)outlineView:(NSOutlineView *)aOutlineView numberOfChildrenOfItem:(id)item
{
NSIndexPath *path = item;
if ((path != nil) && ([path length] == 1)) {
if (_rootChildrenCounts == nil) {
_rootChildrenCounts = [[[self py] rootChildrenCounts] retain];
}
NSInteger index = [path indexAtPosition:0];
return n2i([_rootChildrenCounts objectAtIndex:index]);
}
return [super outlineView:aOutlineView numberOfChildrenOfItem:item];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)column byItem:(id)item
{
NSIndexPath *path = item;
@ -125,6 +139,8 @@ http://www.hardcoded.net/licenses/hs_license
/* Python --> Cocoa */
- (void)refresh /* Override */
{
[_rootChildrenCounts release];
_rootChildrenCounts = nil;
[super refresh];
[outlineView expandItem:nil expandChildren:YES];
}

View File

@ -194,6 +194,9 @@ class PyResultOutline(PyOutline):
def markSelected(self):
self.py.app.toggle_selected_mark_state()
def rootChildrenCounts(self):
return self.py.root_children_counts()
# python --> cocoa
def invalidate_markings(self):
self.cocoa.invalidateMarkings()

View File

@ -88,6 +88,11 @@ class ResultTree(GUIObject, Tree):
else:
return node.data[column]
def root_children_counts(self):
# This is a speed optimization for cases where there's a lot of results so that there is
# not thousands of children_count queries when expandAll is called.
return [len(node) for node in self]
def sort(self, key, asc):
if self.power_marker:
self.app.results.sort_dupes(key, asc, self.delta_values)