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

rjw rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:57:21 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 1c8d1f4306042ffdcf37f19f06321b28f484707e
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Mar 13 23:49:31 2002 +0000

    Added font cache.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@731 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index dfadab2..86568da 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,5 +1,17 @@
 2002-03-13  Richard Williamson  <rjw at apple.com>
 
+        Added font cache.  Attempted to reduce size of fragment cache, but
+        malloc forces a minimum of 30 bytes for our 14 byte objects.
+        
+	* src/kwq/KWQFont.mm: (-[IFFontCacheKey dealloc]), (-[IFFontCacheKey
+	copyWithZone:]), (-[IFFontCacheKey hash]), (-[IFFontCacheKey string]),
+	(-[IFFontCacheKey isEqual:]), (QFont::getFont):
+	* src/kwq/KWQFontMetrics.mm: (-[KWQLayoutFragment setGlyphRangeLength:]):
+	* src/kwq/KWQMetrics.h:
+	* src/kwq/KWQTextStorage.mm: (-[KWQTextStorage addFragmentForString:]):
+
+2002-03-13  Richard Williamson  <rjw at apple.com>
+
         Re-worked fragment cache to minimize memory usage.
         
 	* src/kwq/KWQFontMetrics.mm: (-[KWQLayoutFragment glyphRange]),
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index dfadab2..86568da 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,5 +1,17 @@
 2002-03-13  Richard Williamson  <rjw at apple.com>
 
+        Added font cache.  Attempted to reduce size of fragment cache, but
+        malloc forces a minimum of 30 bytes for our 14 byte objects.
+        
+	* src/kwq/KWQFont.mm: (-[IFFontCacheKey dealloc]), (-[IFFontCacheKey
+	copyWithZone:]), (-[IFFontCacheKey hash]), (-[IFFontCacheKey string]),
+	(-[IFFontCacheKey isEqual:]), (QFont::getFont):
+	* src/kwq/KWQFontMetrics.mm: (-[KWQLayoutFragment setGlyphRangeLength:]):
+	* src/kwq/KWQMetrics.h:
+	* src/kwq/KWQTextStorage.mm: (-[KWQTextStorage addFragmentForString:]):
+
+2002-03-13  Richard Williamson  <rjw at apple.com>
+
         Re-worked fragment cache to minimize memory usage.
         
 	* src/kwq/KWQFontMetrics.mm: (-[KWQLayoutFragment glyphRange]),
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index dfadab2..86568da 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,5 +1,17 @@
 2002-03-13  Richard Williamson  <rjw at apple.com>
 
+        Added font cache.  Attempted to reduce size of fragment cache, but
+        malloc forces a minimum of 30 bytes for our 14 byte objects.
+        
+	* src/kwq/KWQFont.mm: (-[IFFontCacheKey dealloc]), (-[IFFontCacheKey
+	copyWithZone:]), (-[IFFontCacheKey hash]), (-[IFFontCacheKey string]),
+	(-[IFFontCacheKey isEqual:]), (QFont::getFont):
+	* src/kwq/KWQFontMetrics.mm: (-[KWQLayoutFragment setGlyphRangeLength:]):
+	* src/kwq/KWQMetrics.h:
+	* src/kwq/KWQTextStorage.mm: (-[KWQTextStorage addFragmentForString:]):
+
+2002-03-13  Richard Williamson  <rjw at apple.com>
+
         Re-worked fragment cache to minimize memory usage.
         
 	* src/kwq/KWQFontMetrics.mm: (-[KWQLayoutFragment glyphRange]),
diff --git a/WebCore/kwq/KWQFont.mm b/WebCore/kwq/KWQFont.mm
index e0ad7a7..29c8e4c 100644
--- a/WebCore/kwq/KWQFont.mm
+++ b/WebCore/kwq/KWQFont.mm
@@ -89,10 +89,89 @@ void QFont::_free(){
 
 // member functions --------------------------------------------------------
 
+#ifdef DEBUG_GETFONT
+static int getFontCount = 0;
+#endif
+
+static NSMutableDictionary *fontCache = 0;
+
+// IFObjectHolder holds objects as keys in dictionaries without
+// copying.
+ at interface IFFontCacheKey : NSObject
+{
+    NSString *string;
+    int trait;
+    float size;
+}
+
+- initWithString: (NSString *)str trait: (int)t size: (float)s;
+
+ at end
+
+ at implementation IFFontCacheKey
+
+- initWithString: (NSString *)str trait: (int)t size: (float)s;
+{
+    [super init];
+    string = [str retain];
+    trait = t;
+    size = s;
+    return self;
+}
+
+- (void)dealloc
+{
+    [string release];
+    [super dealloc];
+}
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    return [self retain];
+}
+
+- (unsigned)hash
+{
+    return [string hash];
+}
+
+- (NSString *)string
+{
+    return string;
+}
+
+- (int)trait { return trait; }
+- (float)size { return size; }
+
+- (BOOL)isEqual:(id)o
+{
+    IFFontCacheKey *anObject = o;
+    if ([string isEqual: [anObject string]] && trait == [anObject trait] && size == [anObject size])
+        return YES;
+    return NO;
+}
+
+ at end
+
 NSFont *QFont::getFont()
 {
-    if (font == nil)
-        font = [[[NSFontManager sharedFontManager] fontWithFamily:_family traits:_trait weight:5 size:_size] retain];
+    if (font == nil){
+        NSString *fontKey;
+#ifdef DEBUG_GETFONT
+        getFontCount++;
+        fprintf (stdout, "getFountCount = %d, family = %s, traits = 0x%08x, size = %f\n", getFontCount, [_family cString], _trait, _size);
+#endif
+        if (fontCache == nil){
+            fontCache = [[NSMutableDictionary alloc] init];
+        }
+        fontKey = [[IFFontCacheKey alloc] initWithString: _family trait: _trait size: _size];
+        font = [fontCache objectForKey:fontKey];
+        if (font == nil){ 
+            font = [[NSFontManager sharedFontManager] fontWithFamily:_family traits:_trait weight:5 size:_size];
+            [fontCache setObject: font forKey: fontKey];
+        }
+        [fontKey release];
+    }
     return font;
 }
         
diff --git a/WebCore/kwq/KWQFontMetrics.mm b/WebCore/kwq/KWQFontMetrics.mm
index 623666f..9557cb4 100644
--- a/WebCore/kwq/KWQFontMetrics.mm
+++ b/WebCore/kwq/KWQFontMetrics.mm
@@ -49,7 +49,7 @@ const float LargeNumberForText = 1.0e7;
     return glyphRange;
 }
 
-- (void)setGlyphRangeLength: (unsigned int)l
+- (void)setGlyphRangeLength: (unsigned short)l
 {
     glyphRangeLength = l;
 }
diff --git a/WebCore/kwq/KWQMetrics.h b/WebCore/kwq/KWQMetrics.h
index 5f7ebef..7f5f204 100644
--- a/WebCore/kwq/KWQMetrics.h
+++ b/WebCore/kwq/KWQMetrics.h
@@ -51,12 +51,12 @@
 
 @interface KWQLayoutFragment : NSObject
 {
-    NSSize boundingRectSize;  // Is origin always zero?  Only need size.
-    unsigned int glyphRangeLength;  // Is location always zero?  Only need length.
+    NSSize boundingRectSize;
+    unsigned short glyphRangeLength;  // Is location always zero?  Only need length.
 }
 
 
-- (void)setGlyphRangeLength: (unsigned int)l;
+- (void)setGlyphRangeLength: (unsigned short)l;
 - (NSRange)glyphRange;
 - (void)setBoundingRectSize: (NSSize)s;
 - (NSRect)boundingRect;
diff --git a/WebCore/kwq/KWQTextStorage.mm b/WebCore/kwq/KWQTextStorage.mm
index 22b70eb..3dffeaf 100644
--- a/WebCore/kwq/KWQTextStorage.mm
+++ b/WebCore/kwq/KWQTextStorage.mm
@@ -39,6 +39,10 @@
     correct attributes (font and color only) during layout and rendering.
 */
 
+#ifndef UINT16_MAX
+#define UINT16_MAX        65535
+#endif
+
 @implementation KWQTextStorage
 
 - (KWQLayoutFragment *)getFragmentForString: (NSString *)fragString
@@ -68,6 +72,10 @@
         [NSException raise:@"OPTIMIZATION ASSUMPTION VIOLATED" format:@"glyphRange.location != 0"];
     }
 
+    if (glyphRange.length > UINT16_MAX){
+        [NSException raise:@"OPTIMIZATION ASSUMPTION VIOLATED" format:@"glyphRange.length > UINT16_MAX"];
+    }
+    
     [fragment setGlyphRangeLength: glyphRange.length];
     
     NSRect boundingRect = [_layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: [KWQTextContainer sharedInstance]];
diff --git a/WebCore/src/kwq/KWQFont.mm b/WebCore/src/kwq/KWQFont.mm
index e0ad7a7..29c8e4c 100644
--- a/WebCore/src/kwq/KWQFont.mm
+++ b/WebCore/src/kwq/KWQFont.mm
@@ -89,10 +89,89 @@ void QFont::_free(){
 
 // member functions --------------------------------------------------------
 
+#ifdef DEBUG_GETFONT
+static int getFontCount = 0;
+#endif
+
+static NSMutableDictionary *fontCache = 0;
+
+// IFObjectHolder holds objects as keys in dictionaries without
+// copying.
+ at interface IFFontCacheKey : NSObject
+{
+    NSString *string;
+    int trait;
+    float size;
+}
+
+- initWithString: (NSString *)str trait: (int)t size: (float)s;
+
+ at end
+
+ at implementation IFFontCacheKey
+
+- initWithString: (NSString *)str trait: (int)t size: (float)s;
+{
+    [super init];
+    string = [str retain];
+    trait = t;
+    size = s;
+    return self;
+}
+
+- (void)dealloc
+{
+    [string release];
+    [super dealloc];
+}
+
+- (id)copyWithZone:(NSZone *)zone
+{
+    return [self retain];
+}
+
+- (unsigned)hash
+{
+    return [string hash];
+}
+
+- (NSString *)string
+{
+    return string;
+}
+
+- (int)trait { return trait; }
+- (float)size { return size; }
+
+- (BOOL)isEqual:(id)o
+{
+    IFFontCacheKey *anObject = o;
+    if ([string isEqual: [anObject string]] && trait == [anObject trait] && size == [anObject size])
+        return YES;
+    return NO;
+}
+
+ at end
+
 NSFont *QFont::getFont()
 {
-    if (font == nil)
-        font = [[[NSFontManager sharedFontManager] fontWithFamily:_family traits:_trait weight:5 size:_size] retain];
+    if (font == nil){
+        NSString *fontKey;
+#ifdef DEBUG_GETFONT
+        getFontCount++;
+        fprintf (stdout, "getFountCount = %d, family = %s, traits = 0x%08x, size = %f\n", getFontCount, [_family cString], _trait, _size);
+#endif
+        if (fontCache == nil){
+            fontCache = [[NSMutableDictionary alloc] init];
+        }
+        fontKey = [[IFFontCacheKey alloc] initWithString: _family trait: _trait size: _size];
+        font = [fontCache objectForKey:fontKey];
+        if (font == nil){ 
+            font = [[NSFontManager sharedFontManager] fontWithFamily:_family traits:_trait weight:5 size:_size];
+            [fontCache setObject: font forKey: fontKey];
+        }
+        [fontKey release];
+    }
     return font;
 }
         
diff --git a/WebCore/src/kwq/KWQFontMetrics.mm b/WebCore/src/kwq/KWQFontMetrics.mm
index 623666f..9557cb4 100644
--- a/WebCore/src/kwq/KWQFontMetrics.mm
+++ b/WebCore/src/kwq/KWQFontMetrics.mm
@@ -49,7 +49,7 @@ const float LargeNumberForText = 1.0e7;
     return glyphRange;
 }
 
-- (void)setGlyphRangeLength: (unsigned int)l
+- (void)setGlyphRangeLength: (unsigned short)l
 {
     glyphRangeLength = l;
 }
diff --git a/WebCore/src/kwq/KWQMetrics.h b/WebCore/src/kwq/KWQMetrics.h
index 5f7ebef..7f5f204 100644
--- a/WebCore/src/kwq/KWQMetrics.h
+++ b/WebCore/src/kwq/KWQMetrics.h
@@ -51,12 +51,12 @@
 
 @interface KWQLayoutFragment : NSObject
 {
-    NSSize boundingRectSize;  // Is origin always zero?  Only need size.
-    unsigned int glyphRangeLength;  // Is location always zero?  Only need length.
+    NSSize boundingRectSize;
+    unsigned short glyphRangeLength;  // Is location always zero?  Only need length.
 }
 
 
-- (void)setGlyphRangeLength: (unsigned int)l;
+- (void)setGlyphRangeLength: (unsigned short)l;
 - (NSRange)glyphRange;
 - (void)setBoundingRectSize: (NSSize)s;
 - (NSRect)boundingRect;
diff --git a/WebCore/src/kwq/KWQTextStorage.mm b/WebCore/src/kwq/KWQTextStorage.mm
index 22b70eb..3dffeaf 100644
--- a/WebCore/src/kwq/KWQTextStorage.mm
+++ b/WebCore/src/kwq/KWQTextStorage.mm
@@ -39,6 +39,10 @@
     correct attributes (font and color only) during layout and rendering.
 */
 
+#ifndef UINT16_MAX
+#define UINT16_MAX        65535
+#endif
+
 @implementation KWQTextStorage
 
 - (KWQLayoutFragment *)getFragmentForString: (NSString *)fragString
@@ -68,6 +72,10 @@
         [NSException raise:@"OPTIMIZATION ASSUMPTION VIOLATED" format:@"glyphRange.location != 0"];
     }
 
+    if (glyphRange.length > UINT16_MAX){
+        [NSException raise:@"OPTIMIZATION ASSUMPTION VIOLATED" format:@"glyphRange.length > UINT16_MAX"];
+    }
+    
     [fragment setGlyphRangeLength: glyphRange.length];
     
     NSRect boundingRect = [_layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: [KWQTextContainer sharedInstance]];

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list