Changeset 119


Ignore:
Timestamp:
Feb 10, 2006, 6:14:36 AM (16 years ago)
Author:
titer
Message:

Cleaner icon caching

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/NameCell.h

    r112 r119  
    3737    NSString * fPeersString;
    3838
    39     NSMutableArray * fFileTypes;
    40     NSMutableArray * fIcons;
    41     NSImage        * fCurrentIcon;
     39    NSMutableDictionary * fIcons;
     40    NSImage             * fCurrentIcon;
    4241}
    4342- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w;
  • trunk/macosx/NameCell.m

    r112 r119  
    2929- (id) init
    3030{
    31     [super init];
    32 
    33     fFileTypes = [[NSMutableArray alloc] initWithCapacity: 10];
    34     fIcons     = [[NSMutableArray alloc] initWithCapacity: 10];
     31    if ((self = [super init]))
     32        fIcons = [[NSMutableDictionary alloc] initWithCapacity: 10];
    3533
    3634    return self;
    3735}
    3836
     37- (void) dealloc
     38{
     39    [fIcons release];
     40    [super dealloc];
     41}
     42
    3943- (NSImage *) iconForFileType: (NSString *) type
    4044{
    41     unsigned i;
    42 
    43     /* See if we have this icon cached */
    44     for( i = 0; i < [fFileTypes count]; i++ )
    45         if( [[fFileTypes objectAtIndex: i] isEqualToString: type] )
    46             break;
    47 
    48     if( i == [fFileTypes count] )
     45    NSImage * icon;
     46    if (!(icon = [fIcons objectForKey: type]))
    4947    {
    5048        /* Unknown file type, get its icon and cache it */
    51         NSImage * icon;
    5249        icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];
    5350        [icon setFlipped: YES];
    54         [fFileTypes addObject: type];
    55         [fIcons     addObject: icon];
     51
     52        [fIcons setObject: icon forKey: type];
    5653    }
    5754
    58     return [fIcons objectAtIndex: i];
     55    return icon;
    5956}
    6057
     
    137134
    138135    pen.x += 5;
    139     pen.y += 5;                                                                 
     136    pen.y += 5;
    140137    [fCurrentIcon drawAtPoint: pen fromRect:
    141138        NSMakeRect(0,0,[fCurrentIcon size].width,[fCurrentIcon size].height)
Note: See TracChangeset for help on using the changeset viewer.