Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add cache for defaultStyleSheet #167

Merged
merged 2 commits into from

2 participants

Jianjun Oliver Drobnik
Jianjun

hi, bother you again.

Run a time profiling and found [DTCSSStylesheet defaultStyleSheet] taking 13% (about 900ms) when loading a table view with about 30 cells of rich text. Tried adding a cache for defaultStyleSheet, much better now.

Oliver Drobnik
Owner

Good catch!

Oliver Drobnik Cocoanetics merged commit b063124 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2012
  1. Jianjun
Commits on Apr 11, 2012
  1. Jianjun

    add cache for defaultStyleSheet

    tonycn authored
This page is out of date. Refresh to see the latest.
18 Core/Source/DTCSSStylesheet.m
View
@@ -28,11 +28,21 @@ @implementation DTCSSStylesheet
+ (DTCSSStylesheet *)defaultStyleSheet
{
- // get the data from the external symbol
- NSData *data = [NSData dataWithBytes:default_css length:default_css_len];
- NSString *cssString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ static DTCSSStylesheet *defaultDTCSSStylesheet = nil;
+ if (defaultDTCSSStylesheet != nil) {
+ return defaultDTCSSStylesheet;
+ }
- return [[DTCSSStylesheet alloc] initWithStyleBlock:cssString];
+ @synchronized(self) {
+ if (defaultDTCSSStylesheet == nil) {
+ // get the data from the external symbol
+ NSData *data = [NSData dataWithBytes:default_css length:default_css_len];
+ NSString *cssString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+
+ defaultDTCSSStylesheet = [[DTCSSStylesheet alloc] initWithStyleBlock:cssString];
+ }
+ }
+ return defaultDTCSSStylesheet;
}
- (id)initWithStyleBlock:(NSString *)css
10 DTCoreText.xcodeproj/project.pbxproj
View
@@ -1597,7 +1597,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = (
+ "$(ARCHS_STANDARD_32_BIT)",
+ armv6,
+ );
COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/DTCoreText.dst;
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -1622,7 +1625,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = (
+ "$(ARCHS_STANDARD_32_BIT)",
+ armv6,
+ );
COPY_PHASE_STRIP = YES;
DSTROOT = /tmp/DTCoreText.dst;
GCC_C_LANGUAGE_STANDARD = gnu99;
Something went wrong with that request. Please try again.