If I have to optimise something later, I will do it.
You can take advantage of Objective-C's categories to make future
optimization an easier task. For example, rather than coding:
for( unsigned ii = 0; ii < count; ii++ ) {
sum += [[array objectAtIndex:ii] floatValue];
}
Instead do:
@interface NSArray (MYStatsAdditions)
- (float) floatAtIndex:(unsigned)idx ;
@end
@implementation NSArray (MYStatsAdditions)
- (float) floatAtIndex:(unsigned)idx
{
return [[self objectAtIndex:idx] floatValue];
}
@end
for( unsigned ii = 0; ii < count; ii++ ) {
sum += [array floatAtIndex:ii];
}
Then later you can just pop in a custom NSObject subclass that
implements "floatAtIndex" backed by a plain C array without changing
any other code. You could even take this a step further by (perhaps
abusing) categories to add:
@interface NSArray (MYStatsAdditions)
- (float) floatAtIndex:(unsigned)idx ;
- (float) floatSum ;
- (float) floatMedian ;
// etc
@end
At that point it would probably be worth creating a custom object
(eg: MYStatsVector), initially backed by a normal NSArray and only
changing the guts to a plain C array later if needed.
~Martin
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com