mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
improve CPString sizeOfString performance by caching the calculated result
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
@import "CPPlatformString.j"
|
||||
|
||||
var CPStringSizeWithFontInWidthCache = {};
|
||||
|
||||
@implementation CPString (CPStringDrawing)
|
||||
|
||||
@@ -50,7 +51,17 @@
|
||||
|
||||
- (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth
|
||||
{
|
||||
return [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth];
|
||||
var cacheKey = self + [aFont cssString] + aWidth;
|
||||
size = CPStringSizeWithFontInWidthCache[cacheKey];
|
||||
|
||||
if (size === undefined)
|
||||
{
|
||||
size = [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth];
|
||||
CPStringSizeWithFontInWidthCache[cacheKey] = size;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user