More optimisation - don't create cells that we are immediately going to

replace.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5123 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-11-02 21:42:24 +00:00
parent 6e1d7f46a0
commit 7cbbb66f90
2 changed files with 77 additions and 16 deletions

View file

@ -55,6 +55,8 @@ typedef enum _NSMatrixMode {
int maxCols; int maxCols;
int numRows; int numRows;
int numCols; int numCols;
int insertingColWithCells;
int insertingRowWithCells;
NSZone *myZone; NSZone *myZone;
Class cellClass; Class cellClass;
id cellPrototype; id cellPrototype;

View file

@ -49,7 +49,7 @@
#include <AppKit/NSMatrix.h> #include <AppKit/NSMatrix.h>
#define LAX 0 #define STRICT 0
#ifdef MIN #ifdef MIN
# undef MIN # undef MIN
@ -123,6 +123,7 @@ static int mouseDownFlags = 0;
static SEL copySel = @selector(copyWithZone:); static SEL copySel = @selector(copyWithZone:);
static SEL initSel = @selector(init); static SEL initSel = @selector(init);
static SEL allocSel = @selector(allocWithZone:); static SEL allocSel = @selector(allocWithZone:);
static SEL getSel = @selector(objectAtIndex:);
+ (void) initialize + (void) initialize
{ {
@ -272,7 +273,7 @@ static SEL allocSel = @selector(allocWithZone:);
if (column < 0) if (column < 0)
{ {
column = 0; column = 0;
#if LAX #if STRICT == 0
NSLog(@"insert negative column (%d) in matrix", column); NSLog(@"insert negative column (%d) in matrix", column);
#else #else
[NSException raise: NSRangeException [NSException raise: NSRangeException
@ -315,9 +316,21 @@ static SEL allocSel = @selector(allocWithZone:);
- (void) insertColumn: (int)column withCells: (NSArray*)cellArray - (void) insertColumn: (int)column withCells: (NSArray*)cellArray
{ {
int count = [cellArray count]; int count = [cellArray count];
IMP getImp;
int i; int i;
if (count > 0 && (numRows == 0 || numCols == 0)) if (count == 0)
{
[self insertColumn: column];
return;
}
/*
* Set ivar to tell renewRows:columns: how much space to leave for cells
* that will be added from the array.
*/
insertingColWithCells = count;
if (numRows == 0 || numCols == 0)
{ {
/* /*
* MacOS-X docs say that if the matrix is empty, we make it have one * MacOS-X docs say that if the matrix is empty, we make it have one
@ -330,9 +343,10 @@ static SEL allocSel = @selector(allocWithZone:);
[self insertColumn: column]; [self insertColumn: column];
} }
getImp = [cellArray methodForSelector: getSel];
for (i = 0; i < numRows && i < count; i++) for (i = 0; i < numRows && i < count; i++)
{ {
ASSIGN(cells[i][column], [cellArray objectAtIndex: i]); cells[i][column] = RETAIN((*getImp)(cellArray, getSel, i));
} }
if (mode == NSRadioModeMatrix && !allowsEmptySelection && selectedCell == nil) if (mode == NSRadioModeMatrix && !allowsEmptySelection && selectedCell == nil)
@ -346,7 +360,7 @@ static SEL allocSel = @selector(allocWithZone:);
if (row < 0) if (row < 0)
{ {
row = 0; row = 0;
#if LAX #if STRICT == 0
NSLog(@"insert negative row (%d) in matrix", row); NSLog(@"insert negative row (%d) in matrix", row);
#else #else
[NSException raise: NSRangeException [NSException raise: NSRangeException
@ -388,9 +402,21 @@ static SEL allocSel = @selector(allocWithZone:);
- (void) insertRow: (int)row withCells: (NSArray*)cellArray - (void) insertRow: (int)row withCells: (NSArray*)cellArray
{ {
int count = [cellArray count]; int count = [cellArray count];
IMP getImp;
int i; int i;
if (count > 0 && (numRows == 0 || numCols == 0)) if (count == 0)
{
[self insertRow: row];
return;
}
/*
* Set ivar to tell renewRows:columns: how much space to leave for cells
* that will be added from the array.
*/
insertingRowWithCells = count;
if (numRows == 0 || numCols == 0)
{ {
/* /*
* MacOS-X docs say that if the matrix is empty, we make it have one * MacOS-X docs say that if the matrix is empty, we make it have one
@ -403,9 +429,10 @@ static SEL allocSel = @selector(allocWithZone:);
[self insertRow: row]; [self insertRow: row];
} }
getImp = [cellArray methodForSelector: getSel];
for (i = 0; i < numCols && i < count; i++) for (i = 0; i < numCols && i < count; i++)
{ {
ASSIGN(cells[row][i], [cellArray objectAtIndex: i]); cells[row][i] = RETAIN((*getImp)(cellArray, getSel, i));
} }
if (mode == NSRadioModeMatrix && !allowsEmptySelection && selectedCell == nil) if (mode == NSRadioModeMatrix && !allowsEmptySelection && selectedCell == nil)
@ -500,7 +527,7 @@ static SEL allocSel = @selector(allocWithZone:);
} }
else else
{ {
#if LAX #if STRICT == 0
NSLog(@"remove non-existent column (%d) from matrix", col); NSLog(@"remove non-existent column (%d) from matrix", col);
#else #else
[NSException raise: NSRangeException [NSException raise: NSRangeException
@ -539,7 +566,7 @@ static SEL allocSel = @selector(allocWithZone:);
} }
else else
{ {
#if LAX #if STRICT == 0
NSLog(@"remove non-existent row (%d) from matrix", row); NSLog(@"remove non-existent row (%d) from matrix", row);
#else #else
[NSException raise: NSRangeException [NSException raise: NSRangeException
@ -557,7 +584,7 @@ static SEL allocSel = @selector(allocWithZone:);
if (r < 0) if (r < 0)
{ {
#if LAX #if STRICT == 0
NSLog(@"renew negative row (%d) in matrix", r); NSLog(@"renew negative row (%d) in matrix", r);
#else #else
[NSException raise: NSRangeException [NSException raise: NSRangeException
@ -567,7 +594,7 @@ static SEL allocSel = @selector(allocWithZone:);
} }
if (c < 0) if (c < 0)
{ {
#if LAX #if STRICT == 0
NSLog(@"renew negative column (%d) in matrix", c); NSLog(@"renew negative column (%d) in matrix", c);
#else #else
[NSException raise: NSRangeException [NSException raise: NSRangeException
@ -580,6 +607,8 @@ static SEL allocSel = @selector(allocWithZone:);
{ {
for (i = 0; i < maxRows; i++) for (i = 0; i < maxRows; i++)
{ {
int end = c - 1;
cells[i] = NSZoneRealloc(myZone, cells[i], c * sizeof(id)); cells[i] = NSZoneRealloc(myZone, cells[i], c * sizeof(id));
selectedCells[i] = NSZoneRealloc(GSAtomicMallocZone(), selectedCells[i] = NSZoneRealloc(GSAtomicMallocZone(),
selectedCells[i], c * sizeof(BOOL)); selectedCells[i], c * sizeof(BOOL));
@ -588,7 +617,14 @@ static SEL allocSel = @selector(allocWithZone:);
{ {
cells[i][j] = nil; cells[i][j] = nil;
selectedCells[i][j] = NO; selectedCells[i][j] = NO;
(*mkImp)(self, mkSel, i, j); if (j == end && insertingColWithCells > 0)
{
insertingColWithCells--;
}
else
{
(*mkImp)(self, mkSel, i, j);
}
} }
} }
maxCols = c; maxCols = c;
@ -596,6 +632,8 @@ static SEL allocSel = @selector(allocWithZone:);
if (r > maxRows) if (r > maxRows)
{ {
int end = r - 1;
cells = NSZoneRealloc(myZone, cells, r * sizeof(id*)); cells = NSZoneRealloc(myZone, cells, r * sizeof(id*));
selectedCells = NSZoneRealloc(myZone, selectedCells, r * sizeof(BOOL*)); selectedCells = NSZoneRealloc(myZone, selectedCells, r * sizeof(BOOL*));
@ -606,17 +644,38 @@ static SEL allocSel = @selector(allocWithZone:);
selectedCells[i] = NSZoneMalloc(GSAtomicMallocZone(), selectedCells[i] = NSZoneMalloc(GSAtomicMallocZone(),
c * sizeof(BOOL)); c * sizeof(BOOL));
for (j = 0; j < c; j++) if (i == end)
{ {
cells[i][j] = nil; for (j = 0; j < c; j++)
selectedCells[i][j] = NO; {
(*mkImp)(self, mkSel, i, j); cells[i][j] = nil;
selectedCells[i][j] = NO;
if (insertingRowWithCells > 0)
{
insertingRowWithCells--;
}
else
{
(*mkImp)(self, mkSel, i, j);
}
}
}
else
{
for (j = 0; j < c; j++)
{
cells[i][j] = nil;
selectedCells[i][j] = NO;
(*mkImp)(self, mkSel, i, j);
}
} }
} }
maxRows = r; maxRows = r;
} }
numRows = maxRows; numRows = maxRows;
numCols = maxCols; numCols = maxCols;
insertingColWithCells = 0;
insertingRowWithCells = 0;
[self deselectAllCells]; [self deselectAllCells];
} }