Node init performance: Use share instances of UIColor and NSAttributedString for defaults.

This commit is contained in:
Ethan Nagel 2015-08-17 12:23:25 -07:00 committed by rcancro
parent 15975a67e8
commit f7e94f42ed
3 changed files with 30 additions and 2 deletions

View File

@ -60,6 +60,7 @@ extern id ASDisplayNodeFindFirstSubnode(ASDisplayNode *start, BOOL (^block)(ASDi
extern id ASDisplayNodeFindFirstSubnodeOfClass(ASDisplayNode *start, Class c); extern id ASDisplayNodeFindFirstSubnodeOfClass(ASDisplayNode *start, Class c);
extern UIColor *ASDisplayNodeDefaultPlaceholderColor(); extern UIColor *ASDisplayNodeDefaultPlaceholderColor();
extern UIColor *ASDisplayNodeDefaultTintColor();
/** /**
Disable willAppear / didAppear / didDisappear notifications for a sub-hierarchy, then re-enable when done. Nested calls are supported. Disable willAppear / didAppear / didDisappear notifications for a sub-hierarchy, then re-enable when done. Nested calls are supported.

View File

@ -126,7 +126,24 @@ extern id ASDisplayNodeFindFirstSubnodeOfClass(ASDisplayNode *start, Class c)
UIColor *ASDisplayNodeDefaultPlaceholderColor() UIColor *ASDisplayNodeDefaultPlaceholderColor()
{ {
return [UIColor colorWithWhite:0.95 alpha:1.0]; static UIColor *defaultPlaceholderColor;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
defaultPlaceholderColor = [UIColor colorWithWhite:0.95 alpha:1.0];
});
return defaultPlaceholderColor;
}
UIColor *ASDisplayNodeDefaultTintColor()
{
static UIColor *defaultTintColor;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
defaultTintColor = [UIColor colorWithRed:0.0 green:0.478 blue:1.0 alpha:1.0];
});
return defaultTintColor;
} }
#pragma mark - Hierarchy Notifications #pragma mark - Hierarchy Notifications

View File

@ -130,7 +130,7 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
self.needsDisplayOnBoundsChange = YES; self.needsDisplayOnBoundsChange = YES;
_truncationMode = NSLineBreakByWordWrapping; _truncationMode = NSLineBreakByWordWrapping;
_truncationAttributedString = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"\u2026", @"Default truncation string")]; _truncationAttributedString = DefaultTruncationAttributedString();
// The common case is for a text node to be non-opaque and blended over some background. // The common case is for a text node to be non-opaque and blended over some background.
self.opaque = NO; self.opaque = NO;
@ -972,6 +972,16 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
#pragma mark - Truncation Message #pragma mark - Truncation Message
static NSAttributedString *DefaultTruncationAttributedString()
{
static NSAttributedString *defaultTruncationAttributedString;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
defaultTruncationAttributedString = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"\u2026", @"Default truncation string")];
});
return defaultTruncationAttributedString;
}
- (void)setTruncationAttributedString:(NSAttributedString *)truncationAttributedString - (void)setTruncationAttributedString:(NSAttributedString *)truncationAttributedString
{ {
// No-op if they're exactly equal (avoid redrawing) // No-op if they're exactly equal (avoid redrawing)