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

cblu cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:40:33 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 16ede0064fb9c0d378ab2505f197fee000eb9dfa
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Sep 20 16:58:18 2002 +0000

    	Fixed wasteful memory usage in the WebIconDatabase:
    	- Rather than have multiple NSImages with multiple representations at multiple sizes, have 1 NSImage per size
    	- Added API to allow client to control memory caching
    
            * Misc.subproj/WebIconDatabase.h:
            * Misc.subproj/WebIconDatabase.m:
            (-[WebIconDatabase iconForSiteURL:withSize:]): call iconForSiteURL:withSize:cache:YES
            (-[WebIconDatabase iconForSiteURL:withSize:cache:]): new, was iconForSiteURL:withSize:
            (-[WebIconDatabase defaultIconWithSize:]): call _iconFromDictionary:forSize:cache:
            (-[WebIconDatabase _updateFileDatabase]): write the largest icon to disk
            (-[WebIconDatabase _hasIconForSiteURL:]): cleaned-up
            (-[WebIconDatabase _iconsForIconURL:]): call _iconFromDictionary:forSize:cache:
            (-[WebIconDatabase _iconForFileURL:withSize:]): call _iconFromDictionary:forSize:cache:
            (-[WebIconDatabase _builtInIconsForHost:]): call _iconFromDictionary:forSize:cache:
            (-[WebIconDatabase _setIcon:forIconURL:]): _iconsBySplittingRepresentationsOfIcon:
            (-[WebIconDatabase _releaseIconForIconURL:]): icons at different sizes are now stored in dictionaries
            (-[WebIconDatabase _largestIconFromDictionary:]): new, scans the icon dictionary
            (-[WebIconDatabase _iconsBySplittingRepresentationsOfIcon:]): creates the icon dictionary
            (-[WebIconDatabase _iconFromDictionary:forSize:cache:]): returns icon from dict, resizes if necessary
            (-[WebIconDatabase _iconByScalingIcon:toSize:]): tweak
            * Misc.subproj/WebIconDatabasePrivate.h:
            * Misc.subproj/WebIconLoader.m:
            (-[WebIconLoader startLoading]): don't call _iconsForIconURL: because it doesn't exist.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2104 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index e772155..3a4aa53 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,29 @@
+2002-09-20  Chris Blumenberg  <cblu at apple.com>
+
+	Fixed wasteful memory usage in the WebIconDatabase:
+	- Rather than have multiple NSImages with multiple representations at multiple sizes, have 1 NSImage per size
+	- Added API to allow client to control memory caching
+
+        * Misc.subproj/WebIconDatabase.h:
+        * Misc.subproj/WebIconDatabase.m:
+        (-[WebIconDatabase iconForSiteURL:withSize:]): call iconForSiteURL:withSize:cache:YES
+        (-[WebIconDatabase iconForSiteURL:withSize:cache:]): new, was iconForSiteURL:withSize:
+        (-[WebIconDatabase defaultIconWithSize:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _updateFileDatabase]): write the largest icon to disk
+        (-[WebIconDatabase _hasIconForSiteURL:]): cleaned-up 
+        (-[WebIconDatabase _iconsForIconURL:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _iconForFileURL:withSize:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _builtInIconsForHost:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _setIcon:forIconURL:]): _iconsBySplittingRepresentationsOfIcon:
+        (-[WebIconDatabase _releaseIconForIconURL:]): icons at different sizes are now stored in dictionaries
+        (-[WebIconDatabase _largestIconFromDictionary:]): new, scans the icon dictionary
+        (-[WebIconDatabase _iconsBySplittingRepresentationsOfIcon:]): creates the icon dictionary
+        (-[WebIconDatabase _iconFromDictionary:forSize:cache:]): returns icon from dict, resizes if necessary
+        (-[WebIconDatabase _iconByScalingIcon:toSize:]): tweak
+        * Misc.subproj/WebIconDatabasePrivate.h:
+        * Misc.subproj/WebIconLoader.m:
+        (-[WebIconLoader startLoading]): don't call _iconsForIconURL: because it doesn't exist.
+
 2002-09-19  Maciej Stachowiak  <mjs at apple.com>
 
         * Makefile.am: Make `doc' target depend on `all'.
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index e772155..3a4aa53 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,29 @@
+2002-09-20  Chris Blumenberg  <cblu at apple.com>
+
+	Fixed wasteful memory usage in the WebIconDatabase:
+	- Rather than have multiple NSImages with multiple representations at multiple sizes, have 1 NSImage per size
+	- Added API to allow client to control memory caching
+
+        * Misc.subproj/WebIconDatabase.h:
+        * Misc.subproj/WebIconDatabase.m:
+        (-[WebIconDatabase iconForSiteURL:withSize:]): call iconForSiteURL:withSize:cache:YES
+        (-[WebIconDatabase iconForSiteURL:withSize:cache:]): new, was iconForSiteURL:withSize:
+        (-[WebIconDatabase defaultIconWithSize:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _updateFileDatabase]): write the largest icon to disk
+        (-[WebIconDatabase _hasIconForSiteURL:]): cleaned-up 
+        (-[WebIconDatabase _iconsForIconURL:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _iconForFileURL:withSize:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _builtInIconsForHost:]): call _iconFromDictionary:forSize:cache:
+        (-[WebIconDatabase _setIcon:forIconURL:]): _iconsBySplittingRepresentationsOfIcon:
+        (-[WebIconDatabase _releaseIconForIconURL:]): icons at different sizes are now stored in dictionaries
+        (-[WebIconDatabase _largestIconFromDictionary:]): new, scans the icon dictionary
+        (-[WebIconDatabase _iconsBySplittingRepresentationsOfIcon:]): creates the icon dictionary
+        (-[WebIconDatabase _iconFromDictionary:forSize:cache:]): returns icon from dict, resizes if necessary
+        (-[WebIconDatabase _iconByScalingIcon:toSize:]): tweak
+        * Misc.subproj/WebIconDatabasePrivate.h:
+        * Misc.subproj/WebIconLoader.m:
+        (-[WebIconLoader startLoading]): don't call _iconsForIconURL: because it doesn't exist.
+
 2002-09-19  Maciej Stachowiak  <mjs at apple.com>
 
         * Makefile.am: Make `doc' target depend on `all'.
diff --git a/WebKit/Misc.subproj/WebIconDatabase.h b/WebKit/Misc.subproj/WebIconDatabase.h
index 58a1c96..66f79b4 100644
--- a/WebKit/Misc.subproj/WebIconDatabase.h
+++ b/WebKit/Misc.subproj/WebIconDatabase.h
@@ -54,13 +54,22 @@ extern NSSize WebIconLargeSize;  // 128 x 128
 
 /*!
     @method iconForSiteURL:withSize:
+    @discussion Calls iconForSiteURL:withSize:cache: with YES for cache.
+    @param siteURL
+    @param size
+*/
+- (NSImage *)iconForSiteURL:(NSURL *)siteURL withSize:(NSSize)size;
+
+/*!
+    @method iconForSiteURL:withSize:cache:
     @discussion Returns an icon for a web site URL from memory or disk. nil if none is found.
     Usually called by a UI element to determine if a site URL has an associated icon.
-    Also usually called by the observer of WebIconChangedNotification after the notification is sent.
+    Often called by the observer of WebIconChangedNotification after the notification is sent.
     @param siteURL
     @param size
+    @param cache If yes, caches the returned image in memory if not already cached
 */
-- (NSImage *)iconForSiteURL:(NSURL *)siteURL withSize:(NSSize)size;
+- (NSImage *)iconForSiteURL:(NSURL *)siteURL withSize:(NSSize)size cache:(BOOL)cache;
 
 /*!
     @method defaultIconWithSize:
diff --git a/WebKit/Misc.subproj/WebIconDatabase.m b/WebKit/Misc.subproj/WebIconDatabase.m
index 1e7c8a0..d126b9d 100644
--- a/WebKit/Misc.subproj/WebIconDatabase.m
+++ b/WebKit/Misc.subproj/WebIconDatabase.m
@@ -34,10 +34,10 @@ NSSize WebIconLargeSize = {128, 128};
 - (void)_createFileDatabase;
 - (void)_loadIconDictionaries;
 - (void)_updateFileDatabase;
-- (NSMutableArray *)_iconsForIconURL:(NSURL *)iconURL;
+- (NSMutableDictionary *)_iconsForIconURL:(NSURL *)iconURL;
 - (NSImage *)_iconForFileURL:(NSURL *)fileURL withSize:(NSSize)size;
 - (NSString *)_pathForBuiltInIconForHost:(NSString *)host;
-- (NSMutableArray *)_builtInIconsForHost:(NSString *)host;
+- (NSMutableDictionary *)_builtInIconsForHost:(NSString *)host;
 - (void)_retainIconForIconURL:(NSURL *)iconURL;
 - (void)_releaseIconForIconURL:(NSURL *)iconURL;
 - (void)_retainFutureIconForSiteURL:(NSURL *)siteURL;
@@ -47,7 +47,9 @@ NSSize WebIconLargeSize = {128, 128};
 - (void)_sendNotificationForSiteURL:(NSURL *)siteURL;
 - (void)_addObject:(id)object toSetForKey:(id)key inDictionary:(NSMutableDictionary *)dictionary;
 - (NSURL *)_uniqueIconURL;
-- (NSImage *)_cachedIconFromArray:(NSMutableArray *)icons withSize:(NSSize)size;
+- (NSImage *)_largestIconFromDictionary:(NSMutableDictionary *)icons;
+- (NSMutableDictionary *)_iconsBySplittingRepresentationsOfIcon:(NSImage *)icon;
+- (NSImage *)_iconFromDictionary:(NSMutableDictionary *)icons forSize:(NSSize)size cache:(BOOL)cache;
 - (NSImage *)_iconByScalingIcon:(NSImage *)icon toSize:(NSSize)size;
 
 @end
@@ -98,6 +100,11 @@ NSSize WebIconLargeSize = {128, 128};
 
 - (NSImage *)iconForSiteURL:(NSURL *)siteURL withSize:(NSSize)size
 {
+    return [self iconForSiteURL:siteURL withSize:size cache:YES];
+}
+
+- (NSImage *)iconForSiteURL:(NSURL *)siteURL withSize:(NSSize)size cache:(BOOL)cache
+{
     ASSERT(size.width);
     ASSERT(size.height);
     
@@ -109,25 +116,23 @@ NSSize WebIconLargeSize = {128, 128};
         return [self _iconForFileURL:siteURL withSize:size];
     }
 
-    NSMutableArray *icons = [self _builtInIconsForHost:[siteURL host]];
+    NSMutableDictionary *icons = [self _builtInIconsForHost:[siteURL host]];
     
     if(!icons){
         NSURL *iconURL = [_private->siteURLToIconURL objectForKey:siteURL];
         if(!iconURL){
             // Don't have it
-            //NSLog(@"iconForSiteURL no iconURL for siteURL: %@", siteURL);
             return [self defaultIconWithSize:size];
         }
 
         icons = [self _iconsForIconURL:iconURL];
         if(!icons){
             // This should not happen
-            //NSLog(@"iconForSiteURL no icon for iconURL: %@", iconURL);
             return [self defaultIconWithSize:size];
         }        
     }
 
-    return [self _cachedIconFromArray:icons withSize:size];
+    return [self _iconFromDictionary:icons forSize:size cache:cache];
 }
 
 - (NSImage *)defaultIconWithSize:(NSSize)size
@@ -136,15 +141,15 @@ NSSize WebIconLargeSize = {128, 128};
     ASSERT(size.height);
     
     if (!_private->defaultIcons) {
-        NSString *pathForDefaultImage = [[NSBundle bundleForClass:[self class]] pathForResource:@"url_icon" ofType:@"tiff"];
-        if (pathForDefaultImage != nil) {
-            NSImage *icon = [[NSImage alloc] initByReferencingFile: pathForDefaultImage];
-            _private->defaultIcons = [[NSMutableArray arrayWithObject:icon] retain];
+        NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"url_icon" ofType:@"tiff"];
+        if (path) {
+            NSImage *icon = [[NSImage alloc] initByReferencingFile:path];
+            _private->defaultIcons = [[NSMutableDictionary dictionaryWithObject:icon forKey:[NSValue valueWithSize:[icon size]]] retain];
             [icon release];
         }
     }
 
-    return [self _cachedIconFromArray:_private->defaultIcons withSize:size];
+    return [self _iconFromDictionary:_private->defaultIcons forSize:size cache:YES];
 }
 
 - (void)setIcon:(NSImage *)icon forSiteURL:(NSURL *)siteURL
@@ -311,7 +316,7 @@ NSSize WebIconLargeSize = {128, 128};
 
     while ((iconURL = [enumerator nextObject]) != nil) {
         //NSLog(@"writing %@", iconURL);
-        iconData = [[self _iconForIconURL:iconURL] TIFFRepresentation];
+        iconData = [[self _largestIconFromDictionary:[_private->iconURLToIcons objectForKey:iconURL]] TIFFRepresentation];
         if(iconData){
             [fileDB setObject:iconData forKey:iconURL];
             [_private->iconsOnDiskWithURLs addObject:iconURL];
@@ -330,30 +335,22 @@ NSSize WebIconLargeSize = {128, 128};
 
 - (BOOL)_hasIconForSiteURL:(NSURL *)siteURL
 {
-    if([siteURL isFileURL]){
-        return YES;
-    }else if([self _pathForBuiltInIconForHost:[siteURL host]]){
-        return YES;
-    }else if([_private->siteURLToIconURL objectForKey:siteURL]){
+    if([siteURL isFileURL] ||
+       [self _pathForBuiltInIconForHost:[siteURL host]] ||
+       [_private->siteURLToIconURL objectForKey:siteURL]){
         return YES;
-    }else{
-        return NO;
     }
+    
+    return NO;
 }
 
-- (NSImage *)_iconForIconURL:(NSURL *)iconURL
-{
-    // The first item in the icon array is the original non-resized icon
-    return [[self _iconsForIconURL:iconURL] objectAtIndex:0];
-}
-
-- (NSMutableArray *)_iconsForIconURL:(NSURL *)iconURL
+- (NSMutableDictionary *)_iconsForIconURL:(NSURL *)iconURL
 {
     if(!iconURL){
         return nil;
     }
 
-    NSMutableArray *icons = [_private->iconURLToIcons objectForKey:iconURL];
+    NSMutableDictionary *icons = [_private->iconURLToIcons objectForKey:iconURL];
     double start, duration;
     
     if(!icons){
@@ -365,13 +362,11 @@ NSSize WebIconLargeSize = {128, 128};
             
             if(iconData){
                 NSImage *icon = [[NSImage alloc] initWithData:iconData];
-                if(icon){
+                icons = [self _iconsBySplittingRepresentationsOfIcon:icon];
+
+                if(icons){
                     duration = CFAbsoluteTimeGetCurrent() - start;
                     LOG(Timing, "loading and creating icon %@ took %f seconds", iconURL, duration);
-                    
-                    // Cache it
-                    icons = [NSMutableArray arrayWithObject:icon];
-                    [icon release];
                     [_private->iconURLToIcons setObject:icons forKey:iconURL];
                 }
             }
@@ -393,9 +388,9 @@ NSSize WebIconLargeSize = {128, 128};
     if([[[fileURL path] pathExtension] rangeOfString:@"htm"].length > 0){
         if(!_private->htmlIcons){
             icon = [workspace iconForFileType:@"html"];
-            _private->htmlIcons = [[NSMutableArray arrayWithObject:icon] retain];
+            _private->htmlIcons = [[self _iconsBySplittingRepresentationsOfIcon:icon] retain];
         }
-        return [self _cachedIconFromArray:_private->htmlIcons withSize:size];
+        return [self _iconFromDictionary:_private->htmlIcons forSize:size cache:YES];
     }else{
         icon = [workspace iconForFile:[fileURL path]];
         return [self _iconByScalingIcon:icon toSize:size];
@@ -426,17 +421,17 @@ NSSize WebIconLargeSize = {128, 128};
     return nil;
 }
 
-- (NSMutableArray *)_builtInIconsForHost:(NSString *)host
+- (NSMutableDictionary *)_builtInIconsForHost:(NSString *)host
 {
     NSString *path = [self _pathForBuiltInIconForHost:host];
-    NSMutableArray *icons = nil;
+    NSMutableDictionary *icons = nil;
     
     if(path){
         icons = [_private->pathToBuiltInIcons objectForKey:path];    
         if(!icons){
             NSImage *icon = [[NSImage alloc] initWithContentsOfFile:path];
             if(icon){
-                icons = [NSMutableArray arrayWithObject:icon];
+                icons = [self _iconsBySplittingRepresentationsOfIcon:icon];
                 [_private->pathToBuiltInIcons setObject:icons forKey:path];
                 [icon release];
             }
@@ -452,10 +447,16 @@ NSSize WebIconLargeSize = {128, 128};
         return;
     }
 
-    NSMutableArray *icons = [_private->iconURLToIcons objectForKey:iconURL];
+    NSMutableDictionary *icons = [_private->iconURLToIcons objectForKey:iconURL];
     [icons removeAllObjects];
+
+    icons = [self _iconsBySplittingRepresentationsOfIcon:icon];
+
+    if(!icons){
+        return;
+    }
     
-    [_private->iconURLToIcons setObject:[NSMutableArray arrayWithObject:icon] forKey:iconURL];
+    [_private->iconURLToIcons setObject:icons forKey:iconURL];
 
     [self _retainIconForIconURL:iconURL];
     
@@ -556,7 +557,7 @@ NSSize WebIconLargeSize = {128, 128};
         }
 
         // Remove the icon's images
-        NSMutableArray *icons = [_private->iconURLToIcons objectForKey:iconURL];
+        NSMutableDictionary *icons = [_private->iconURLToIcons objectForKey:iconURL];
         [icons removeAllObjects];
         [_private->iconURLToIcons removeObjectForKey:iconURL];
 
@@ -685,28 +686,67 @@ NSSize WebIconLargeSize = {128, 128};
     return uniqueURL;
 }
 
-- (NSImage *)_cachedIconFromArray:(NSMutableArray *)icons withSize:(NSSize)size
+- (NSImage *)_largestIconFromDictionary:(NSMutableDictionary *)icons
 {
-    ASSERT(size.width);
-    ASSERT(size.height);
-    
-    NSEnumerator *enumerator = [icons objectEnumerator];
-    NSImage *icon;
-    
-    while ((icon = [enumerator nextObject]) != nil) {
-        if(NSEqualSizes([icon size], size)){
-            return icon;
+    NSEnumerator *enumerator = [icons keyEnumerator];
+    NSValue *currentSize, *largestSize=nil;
+    float currentSizeArea, largestSizeArea=0;
+    NSSize currentSizeSize;
+
+    while ((currentSize = [enumerator nextObject]) != nil) {
+        currentSizeSize = [currentSize sizeValue];
+        currentSizeArea = currentSizeSize.width * currentSizeSize.height;
+        if(!largestSizeArea || (currentSizeArea > largestSizeArea)){
+            largestSize = currentSize;
+            largestSizeArea = currentSizeArea;
         }
     }
 
-    // The first item in the icon array is the original non-resized icon
-    // Assume that it's best to resize the original
-    NSImage *originalIcon = [icons objectAtIndex:0];
-    icon = [[originalIcon copy] autorelease];
-    icon = [self _iconByScalingIcon:icon toSize:size];
+    return [icons objectForKey:largestSize];
+}
+
+- (NSMutableDictionary *)_iconsBySplittingRepresentationsOfIcon:(NSImage *)icon
+{
+    if(!icon){
+        return nil;
+    }
+
+    NSMutableDictionary *icons = [NSMutableDictionary dictionary];
+    NSEnumerator *enumerator = [[icon representations] objectEnumerator];
+    NSImageRep *rep;
+    NSImage *subIcon;
+    NSSize size;
+
+    while ((rep = [enumerator nextObject]) != nil) {
+        size = [rep size];
+        subIcon = [[NSImage alloc] initWithSize:size];
+        [subIcon addRepresentation:rep];
+        [icons setObject:subIcon forKey:[NSValue valueWithSize:size]];
+        [subIcon release];
+    }
+
+    if([icons count] > 0){
+        return icons;
+    }
+
+    return nil;
+}
 
-    // Cache it
-    [icons addObject:icon];
+- (NSImage *)_iconFromDictionary:(NSMutableDictionary *)icons forSize:(NSSize)size cache:(BOOL)cache
+{
+    ASSERT(size.width);
+    ASSERT(size.height);
+
+    NSImage *icon = [icons objectForKey:[NSValue valueWithSize:size]];
+
+    if(!icon){
+        icon = [[[self _largestIconFromDictionary:icons] copy] autorelease];
+        icon = [self _iconByScalingIcon:icon toSize:size];
+
+        if(cache){
+            [icons setObject:icon forKey:[NSValue valueWithSize:size]];
+        }
+    }
 
     return icon;
 }
@@ -732,7 +772,7 @@ NSSize WebIconLargeSize = {128, 128};
         [currentContent setImageInterpolation:NSImageInterpolationHigh];
         [icon drawInRect:NSMakeRect(0, 0, size.width, size.height)
                 fromRect:NSMakeRect(0, 0, originalSize.width, originalSize.height)
-            operation:NSCompositeSourceOver	// Renders transparency correctly
+               operation:NSCompositeSourceOver	// Renders transparency correctly
                 fraction:1.0];
         [scaledIcon unlockFocus];
         
diff --git a/WebKit/Misc.subproj/WebIconDatabasePrivate.h b/WebKit/Misc.subproj/WebIconDatabasePrivate.h
index cce92fa..179953d 100644
--- a/WebKit/Misc.subproj/WebIconDatabasePrivate.h
+++ b/WebKit/Misc.subproj/WebIconDatabasePrivate.h
@@ -34,17 +34,14 @@
     BOOL didCleanup;
     BOOL waitingToCleanup;
 
-    NSMutableArray *htmlIcons;
-    NSMutableArray *defaultIcons;
+    NSMutableDictionary *htmlIcons;
+    NSMutableDictionary *defaultIcons;
 }
 
 @end
 
 @interface WebIconDatabase (WebPrivate)
 
-// Called by WebIconLoader to determine if a load is necessary.
-- (NSImage *)_iconForIconURL:(NSURL *)iconURL;
-
 // Called by WebIconLoader after loading an icon.
 - (void)_setIcon:(NSImage *)icon forIconURL:(NSURL *)iconURL;
 
diff --git a/WebKit/Misc.subproj/WebIconLoader.m b/WebKit/Misc.subproj/WebIconLoader.m
index 85d162b..681f3c0 100644
--- a/WebKit/Misc.subproj/WebIconLoader.m
+++ b/WebKit/Misc.subproj/WebIconLoader.m
@@ -82,12 +82,6 @@
     if (_private->handle != nil) {
         return;
     }
-
-    NSImage *icon = [[WebIconDatabase sharedIconDatabase] _iconForIconURL:_private->URL];
-    if (icon) {
-        [_private->delegate iconLoader:self receivedPageIcon:icon];
-        return;
-    }
     
     WebResourceRequest *request = [[WebResourceRequest alloc] initWithURL:_private->URL];
     _private->handle = [[WebResourceHandle alloc] initWithRequest:request client:self];

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list