[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:40:35 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 255faa176d05b91b1f7b09e21a06027422b0c125
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue May 6 16:20:58 2003 +0000

            Reviewed by Ken.
    
            - used ObjectAlloc to find large numbers of allocations on startup and get rid of some
    
            * History.subproj/WebHistoryItem.m:
            (-[WebHistoryItem initFromDictionaryRepresentation:]):
            Use the init method that takes a URL string so we don't have to create and then
            destroy a URL for each item we decode.
            * History.subproj/WebHistoryPrivate.m:
            (-[WebHistoryPrivate addItem:]): Use URLString instead of making and destroying
            a URL each time this is called.
            (-[WebHistoryPrivate removeItem:]): Ditto.
            (-[WebHistoryPrivate _loadHistoryGuts:URL:error:]): Check URLString for nil; no reason
            to construct and then destroy a URL just to check validity.
    
            * WebCoreSupport.subproj/WebTextRendererFactory.m:
            (FontCacheKeyCopy): Added.
            (FontCacheKeyFree): Added.
            (FontCacheKeyEqual): Added.
            (FontCacheKeyHash): Added.
            (FontCacheValueRetain): Added.
            (FontCacheValueRelease): Added.
            (-[WebTextRendererFactory cachedFontFromFamily:traits:size:]): Use a C struct for the
            font cache key instead of using an Objective-C object. This saves us an object
            allocation and deallocation when doing a lookup. Also took advantage of the CFDictionary
            ability to store NULL and distinguish it from "not found" so we don't need a separate set
            for cache misses.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@4284 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 2eacc10..5443bc1 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,33 @@
+2003-05-06  Darin Adler  <darin at apple.com>
+
+        Reviewed by Ken.
+
+        - used ObjectAlloc to find large numbers of allocations on startup and get rid of some
+
+        * History.subproj/WebHistoryItem.m:
+        (-[WebHistoryItem initFromDictionaryRepresentation:]):
+        Use the init method that takes a URL string so we don't have to create and then
+        destroy a URL for each item we decode.
+        * History.subproj/WebHistoryPrivate.m:
+        (-[WebHistoryPrivate addItem:]): Use URLString instead of making and destroying
+        a URL each time this is called.
+        (-[WebHistoryPrivate removeItem:]): Ditto.
+        (-[WebHistoryPrivate _loadHistoryGuts:URL:error:]): Check URLString for nil; no reason
+        to construct and then destroy a URL just to check validity.
+        
+        * WebCoreSupport.subproj/WebTextRendererFactory.m:
+        (FontCacheKeyCopy): Added.
+        (FontCacheKeyFree): Added.
+        (FontCacheKeyEqual): Added.
+        (FontCacheKeyHash): Added.
+        (FontCacheValueRetain): Added.
+        (FontCacheValueRelease): Added.
+        (-[WebTextRendererFactory cachedFontFromFamily:traits:size:]): Use a C struct for the
+        font cache key instead of using an Objective-C object. This saves us an object
+        allocation and deallocation when doing a lookup. Also took advantage of the CFDictionary
+        ability to store NULL and distinguish it from "not found" so we don't need a separate set
+        for cache misses.
+
 2003-05-05  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Richard.
diff --git a/WebKit/History.subproj/WebHistoryItem.m b/WebKit/History.subproj/WebHistoryItem.m
index 3fa8636..f757f19 100644
--- a/WebKit/History.subproj/WebHistoryItem.m
+++ b/WebKit/History.subproj/WebHistoryItem.m
@@ -515,16 +515,15 @@ static NSString *WebDisplayTitleKey = @"displayTitle";
     NSString *URLString = [dict _web_stringForKey:@""];
     NSString *title = [dict _web_stringForKey:WebTitleKey];
 
-    self = [self initWithURL:(URLString ? [NSURL _web_URLWithString:URLString] : nil) title:title];
-
-    [self setAlternateTitle:[dict _web_stringForKey:WebDisplayTitleKey]];
-
     // Do an existence check to avoid calling doubleValue on a nil string. Leave
     // time interval at 0 if there's no value in dict.
     NSString *timeIntervalString = [dict _web_stringForKey:WebLastVisitedTimeIntervalKey];
-    if (timeIntervalString != nil) {
-        _private->lastVisitedTimeInterval = [timeIntervalString doubleValue];
-    }
+    NSTimeInterval lastVisited = timeIntervalString == nil ? 0 : [timeIntervalString doubleValue];
+
+    self = [self initWithURLString:URLString title:title lastVisitedTimeInterval:lastVisited];
+
+    [self setAlternateTitle:[dict _web_stringForKey:WebDisplayTitleKey]];
+
     _private->visitCount = [dict _web_intForKey:WebVisitCountKey];
 
     NSArray *childDicts = [dict objectForKey:WebChildrenKey];
diff --git a/WebKit/History.subproj/WebHistoryPrivate.m b/WebKit/History.subproj/WebHistoryPrivate.m
index bb79ce0..c24e044 100644
--- a/WebKit/History.subproj/WebHistoryPrivate.m
+++ b/WebKit/History.subproj/WebHistoryPrivate.m
@@ -150,7 +150,7 @@ NSString *DatesArrayKey = @"WebHistoryDates";
 #ifdef FIX_VISITED
     URLString = [[[entry URL] _web_canonicalize] absoluteString];
 #else
-    URLString = [[entry URL] absoluteString];
+    URLString = [entry URLString];
 #endif
 
     // If we already have an item with this URL, we need to merge info that drives the
@@ -182,7 +182,7 @@ NSString *DatesArrayKey = @"WebHistoryDates";
 #ifdef FIX_VISITED
     URLString = [[[entry URL] _web_canonicalize] absoluteString];
 #else
-    URLString = [[entry URL] absoluteString];
+    URLString = [entry URLString];
 #endif
 
     // If this exact object isn't stored, then make no change.
@@ -405,9 +405,8 @@ NSString *DatesArrayKey = @"WebHistoryDates";
 
         entry = [[[WebHistoryItem alloc] initFromDictionaryRepresentation:itemAsDictionary] autorelease];
 
-        if ([entry URL] == nil) {
-            // entry without URL is useless; data on disk must have been bad; ignore this one
-            // entry without lastVisitDate should never happen; ignore that one
+        if ([entry URLString] == nil) {
+            // entry without URL is useless; data on disk must have been bad; ignore
             continue;
         }
 
diff --git a/WebKit/WebCoreSupport.subproj/WebTextRendererFactory.m b/WebKit/WebCoreSupport.subproj/WebTextRendererFactory.m
index 076f2ed..b3e3354 100644
--- a/WebKit/WebCoreSupport.subproj/WebTextRendererFactory.m
+++ b/WebKit/WebCoreSupport.subproj/WebTextRendererFactory.m
@@ -33,55 +33,6 @@
 - (BOOL)_isFakeFixedPitch;
 @end
 
- at interface WebFontCacheKey : NSObject
-{
-    NSString *family;
-    NSFontTraitMask traits;
-    float size;
-}
-
-- initWithFamily:(NSString *)f traits:(NSFontTraitMask)t size:(float)s;
-
- at end
-
- at implementation WebFontCacheKey
-
-- initWithFamily:(NSString *)f traits:(NSFontTraitMask)t size:(float)s;
-{
-    [super init];
-    family = [f copy];
-    traits = t;
-    size = s;
-    return self;
-}
-
-- (void)dealloc
-{
-    [family release];
-    [super dealloc];
-}
-
-- (id)copyWithZone:(NSZone *)zone
-{
-    return [self retain];
-}
-
-- (unsigned)hash
-{
-    return [family hash] ^ traits ^ (int)size;
-}
-
-- (BOOL)isEqual:(id)o
-{
-    WebFontCacheKey *other = o;
-    return [self class] == [other class]
-        && [family isEqualToString:other->family]
-        && traits == other->traits
-        && size == other->size;
-}
-
- at end
-
 @implementation WebTextRendererFactory
 
 - (BOOL)coalesceTextDrawing
@@ -450,42 +401,88 @@ static BOOL betterChoice(NSFontTraitMask desiredTraits, int desiredWeight,
     return [[NSFontManager sharedFontManager] fontWithFamily:availableFamily traits:chosenTraits weight:chosenWeight size:size];
 }
 
+typedef struct {
+    NSString *family;
+    NSFontTraitMask traits;
+    float size;
+} FontCacheKey;
+
+static const void *FontCacheKeyCopy(CFAllocatorRef allocator, const void *value)
+{
+    const FontCacheKey *key = (const FontCacheKey *)value;
+    FontCacheKey *result = malloc(sizeof(FontCacheKey));
+    result->family = [key->family copy];
+    result->traits = key->traits;
+    result->size = key->size;
+    return result;
+}
+
+static void FontCacheKeyFree(CFAllocatorRef allocator, const void *value)
+{
+    const FontCacheKey *key = (const FontCacheKey *)value;
+    [key->family release];
+    free((void *)key);
+}
+
+static Boolean FontCacheKeyEqual(const void *value1, const void *value2)
+{
+    const FontCacheKey *key1 = (const FontCacheKey *)value1;
+    const FontCacheKey *key2 = (const FontCacheKey *)value2;
+    return key1->size == key2->size && key1->traits == key2->traits && [key1->family isEqualToString:key2->family];
+}
+
+static CFHashCode FontCacheKeyHash(const void *value)
+{
+    const FontCacheKey *key = (const FontCacheKey *)value;
+    return [key->family hash] ^ key->traits ^ (int)key->size;
+}
+
+static const void *FontCacheValueRetain(CFAllocatorRef allocator, const void *value)
+{
+    if (value != NULL) {
+        CFRetain(value);
+    }
+    return value;
+}
+
+static void FontCacheValueRelease(CFAllocatorRef allocator, const void *value)
+{
+    if (value != NULL) {
+        CFRelease(value);
+    }
+}
+
 - (NSFont *)cachedFontFromFamily:(NSString *)family traits:(NSFontTraitMask)traits size:(float)size
 {
-    static NSMutableDictionary *fontCache = nil;
-    static NSMutableSet *missingFonts = nil;
-    WebFontCacheKey *fontKey;
-    NSFont *font = nil;
-    
-    if ([family length] == 0)
-        return nil;
+    ASSERT(family);
     
+    static CFMutableDictionaryRef fontCache = NULL;
     if (!fontCache) {
-        fontCache = [[NSMutableDictionary alloc] init];
+        static const CFDictionaryKeyCallBacks fontCacheKeyCallBacks = { 0, FontCacheKeyCopy, FontCacheKeyFree, NULL, FontCacheKeyEqual, FontCacheKeyHash };
+        static const CFDictionaryValueCallBacks fontCacheValueCallBacks = { 0, FontCacheValueRetain, FontCacheValueRelease, NULL, NULL };
+        fontCache = CFDictionaryCreateMutable(NULL, 0, &fontCacheKeyCallBacks, &fontCacheValueCallBacks);
     }
 
-    fontKey = [[WebFontCacheKey alloc] initWithFamily:family traits:traits size:size];
-    font = [fontCache objectForKey:fontKey];
-    if (!font){
-        if (![missingFonts containsObject:fontKey]){
-            font = [self fontWithFamily:family traits:traits size:size];
-            if (font)
-                [fontCache setObject:font forKey:fontKey];
-            else{
-                if (!missingFonts)
-                    missingFonts = [[NSMutableSet alloc] init];
-                [missingFonts addObject:fontKey];
-            }
+    const FontCacheKey fontKey = { family, traits, size };
+    const void *value;
+    NSFont *font;
+    if (CFDictionaryGetValueIfPresent(fontCache, &fontKey, &value)) {
+        font = (NSFont *)value;
+    } else {
+        if ([family length] == 0) {
+            return nil;
         }
+        font = [self fontWithFamily:family traits:traits size:size];
+        CFDictionaryAddValue(fontCache, &fontKey, font);
     }
+    
 #ifdef DEBUG_MISSING_FONT
     static int unableToFindFontCount = 0;
-    if (font == nil){
+    if (font == nil) {
         unableToFindFontCount++;
-        NSLog (@"unableToFindFontCount %@, traits 0x%08x, size %f, %d\n", family, traits, size, unableToFindFontCount);
+        NSLog(@"unableToFindFontCount %@, traits 0x%08x, size %f, %d\n", family, traits, size, unableToFindFontCount);
     }
 #endif
-    [fontKey release];
     
     return font;
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list