From 54a83734c4aaed9bb45a8d0d3b6287a6e80e446b Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 3 Sep 2000 19:19:40 +0000 Subject: [PATCH] Enclosed creation of a matrix column into an autorelease pool; do not create then destroy a column in the matrix if it is void git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@7351 72102866-910b-0410-8b05-ffd578937521 --- Source/NSSavePanel.m | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Source/NSSavePanel.m b/Source/NSSavePanel.m index 85fa2cea8..8b5b6448e 100644 --- a/Source/NSSavePanel.m +++ b/Source/NSSavePanel.m @@ -709,6 +709,10 @@ createRowsForColumn: (int)column unsigned base_frac = 1; BOOL display_progress = NO; NSString* progressString = nil; + /* We create lot of objects in this method, so we use a pool */ + NSAutoreleasePool *pool; + + pool = [NSAutoreleasePool new]; path = [_browser pathToColumn: column]; files = [_fm directoryContentsAtPath: path]; @@ -727,7 +731,10 @@ createRowsForColumn: (int)column // if array is empty, just return (nothing to display) if (count == 0) - return; + { + RELEASE (pool); + return; + } // Prepare Messages on title bar if directory is big and user wants them if (_gs_display_reading_progress && (count > 100)) @@ -758,8 +765,6 @@ createRowsForColumn: (int)column else files = [files sortedArrayUsingSelector: @selector(compare:)]; - // Create the column. - [matrix addColumn]; addedRows = 0; for (i = 0; i < count; i++) { @@ -803,8 +808,18 @@ createRowsForColumn: (int)column if (exists) { - if (addedRows >0) - [matrix addRow]; + if (addedRows == 0) + { + [matrix addColumn]; + } + else // addedRows > 0 + { + /* Same as [matrix addRow] */ + [matrix insertRow: addedRows withCells: nil]; + /* Possible TODO: Faster would be to create all the + cells at once with a single call instead of resizing + the matrix each time a cell is inserted. */ + } cell = [matrix cellAtRow: addedRows column: 0]; [cell setStringValue: file]; @@ -818,14 +833,13 @@ createRowsForColumn: (int)column } } - if (addedRows == 0) - [matrix removeColumn: 0]; - if (display_progress) { [super setTitle: @""]; [GSCurrentContext() flush]; } + + RELEASE (pool); } - (BOOL) browser: (NSBrowser*)sender @@ -874,7 +888,7 @@ selectCellWithString: (NSString*)title [[_form cellAtIndex: 0] setStringValue: @""]; [_form setNeedsDisplay: YES]; } - + return YES; }