Re: NSTableView
Re: NSTableView
- Subject: Re: NSTableView
- From: David Blanton <email@hidden>
- Date: Wed, 14 Jan 2009 12:47:31 -0700
Holy Joker Batman!
Changing
return cell;
to
return cell->_value
gives the performance I am looking for!
Corbin, u 2 cool!
Thanks.
On Jan 14, 2009, at 12:38 PM, Corbin Dunn wrote:
I still reiterate that you need a Shark sample to really find the
source of the problem. A complete backtrace during the slowdown is
really what we would need to see, not that it is slow in objc_msgSend.
Overall, the code can/should be improved. Specifically:
/* tableViewobjectValueForTableColumn:row */
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)
rowIndex {
DTVCell* cell = [aTableColumn dataCell];
NSString* colID = [aTableColumn identifier];
[self setupCell:cell forRow:rowIndex column:colID];
return cell;
}
You should not return a cell from this method; you should return
the object value for the cell. This method shouldn't do anything
with a cell; instead, you should setup the cell's properties in -
willDisplayCell. That alone may help you with performance...but, as
I said..a Shark trace would be needed to see the real issue. If you
need steps for getting a good trace, let us know..
corbin
/* setupCell */
- (void)setupCell:(DTVCell*)cell forRow:(int)rowIndex column:
(NSString*)colID {
BMatrixCell *xcell = [_browserCells objectAtIndex:rowIndex];
BEUtil beu;
if(xcell->_haveDesign == NO)
{
BEDesign design;
xcell->m_Design.SetFilename(xcell->mBFilename);
beu.GetFile(xcell->m_Design);
xcell->m_StitchCount = xcell->m_Design.StitchCount();
BEColorList becl;
xcell->m_Design.GetColorList(&becl);
xcell->m_ColorCount = becl.GetCount();
if(xcell->m_ColorCount>0) xcell->m_StitchCount -= (xcell-
>m_ColorCount-1);
xcell->_haveDesign = YES;
}
if([colID compare:@"NAME"] == NSOrderedSame)
{
if(xcell->_name == nil)
{
Str s((const STRCHAR*)xcell->mBFilename.StripExtension());
xcell->_name = [NSString stringWithCString:(const char *)s
encoding:NSASCIIStringEncoding];
[xcell->_name retain];
}
cell->_value = xcell->_name;
return;
}
if([colID compare:@"EXTENSION"] == NSOrderedSame)
{
if(xcell->_extension == nil)
{
Str s((const STRCHAR*)xcell->mBFilename.GetExtension());
xcell->_extension = [NSString stringWithCString:(const char *)s
encoding:NSASCIIStringEncoding];
[xcell->_extension retain];
}
cell->_value = xcell->_extension;
return;
}
if([colID compare:@"COLORS"] == NSOrderedSame)
{
if(xcell->_colors == nil)
{
xcell->_colors = [NSString stringWithFormat:@"%d",xcell-
>m_ColorCount];
[xcell->_colors retain];
}
cell->_value = xcell->_colors;
return;
}
if([colID compare:@"STITCHES"] == NSOrderedSame)
{
if(xcell->_stitches == nil)
{
xcell->_stitches = [NSString stringWithFormat:@"%d",xcell-
>m_StitchCount];
[xcell->_stitches retain];
}
cell->_value = xcell->_stitches;
return;
}
if([colID compare:@"JUMPS"] == NSOrderedSame)
{
if(xcell->m_jumps == 0)
{
BEObj *obj;
POSITION pos = xcell->m_Design.GetHeadPosition();
while(pos)
{
obj = &xcell->m_Design.GetNext(pos);
obj->SetStitchCounts();
int jmp;
obj->m_data.GetData("CIMJUMPS",jmp);
xcell->m_jumps += jmp;
}
xcell->_jumps = [NSString stringWithFormat:@"%d",xcell->m_jumps];
[xcell->_jumps retain];
}
cell->_value = xcell->_jumps;
return;
}
if([colID compare:@"SIZE"] == NSOrderedSame)
{
if(xcell->_size == nil)
{
Str measure((const STRCHAR *)beu.GetMeasureString(1,xcell-
>m_Design));
NSString *nsMeasure = [NSString stringWithCString:(const
STRCHAR*)measure encoding:NSASCIIStringEncoding];
NSRange range = [nsMeasure rangeOfString:@":"];
NSString *sz = [nsMeasure substringToIndex:range.location];
range = [sz rangeOfString:@"mm"];
NSString *w = [sz substringToIndex:range.location];
NSString *h = [sz substringFromIndex:range.location + 2];
sz = [w stringByAppendingString:h];
xcell->_size = [sz substringToIndex:[sz length]-3];
[xcell->_size retain];
}
cell->_value = xcell->_size;
return;
}
if([colID compare:@"DATE"] == NSOrderedSame)
{
if(xcell->_date == nil)
{
Str dir((const STRCHAR*)xcell->mBFilename.GetDirectory());
Str file((const STRCHAR*)xcell->mBFilename.GetFileName());
NSString *nsdir = [NSString stringWithCString:(const char *)dir
encoding:NSASCIIStringEncoding];
NSString *nsfile = [NSString stringWithCString:(const char *)
file encoding:NSASCIIStringEncoding];
nsdir = [nsdir stringByAppendingPathComponent:nsfile];
NSDictionary *dict = [_fileManager fileAttributesAtPath:nsdir
traverseLink:YES];
NSDate *date = [dict objectForKey:NSFileModificationDate];
xcell->_date = [date description];
xcell->_date = [xcell->_date substringToIndex:20];
[xcell->_date retain];
}
cell->_value = xcell->_date;
}
}
On Jan 14, 2009, at 11:30 AM, Andy Lee wrote:
On Jan 14, 2009, at 1:06 PM, Andy Lee wrote:
I forget if you said whether you're using bindings or a data
source. If you're using a data source, how about posting your
code for numberOfRowsInTableView: and
tableView:objectValueForTableColumn:row:? The docs for these
two methods say they need to be very efficient.
I found your earlier post. It sounds like you already know
tableView:objectValueForTableColumn:row: is slow. *Why* is it
slow? Is it making some kind of network or database call? If
your table only has 30 rows or so, why not cache the objects in
an NSArray? Again, posting code might help.
--Andy
David Blanton
David Blanton
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden