[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:29 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit c1d9c1515e0e55aefbde708fa2a5ba4540921477
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Mar 15 00:02:49 2002 +0000
Attempted implementation of space optimizations. Disabled for now.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@741 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index d0ad12a..7bd0638 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,5 +1,17 @@
2002-03-14 Richard Williamson <rjw at apple.com>
+ Attempted implementation of space optimizations. Disabled for now.
+
+ * src/kwq/KWQFontMetrics.mm: (+[KWQLayoutInfo _dumpLayoutCache:]),
+ (-[KWQLayoutInfo rectForString:]):
+ * src/kwq/KWQMetrics.h:
+ * src/kwq/KWQTextStorage.h:
+ * src/kwq/KWQTextStorage.mm: (-[KWQTextStorage _buildFragmentForString:]),
+ (-[KWQTextStorage getFragmentForString:]), (-[KWQTextStorage
+ initWithFontAttribute:]), (-[KWQTextStorage addLayoutManager:]):
+
+2002-03-14 Richard Williamson <rjw at apple.com>
+
Implemented a progressively cache fragment.
* src/kwq/KWQFontMetrics.mm: (-[KWQSmallLayoutFragment setGlyphRange:]),
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index d0ad12a..7bd0638 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,5 +1,17 @@
2002-03-14 Richard Williamson <rjw at apple.com>
+ Attempted implementation of space optimizations. Disabled for now.
+
+ * src/kwq/KWQFontMetrics.mm: (+[KWQLayoutInfo _dumpLayoutCache:]),
+ (-[KWQLayoutInfo rectForString:]):
+ * src/kwq/KWQMetrics.h:
+ * src/kwq/KWQTextStorage.h:
+ * src/kwq/KWQTextStorage.mm: (-[KWQTextStorage _buildFragmentForString:]),
+ (-[KWQTextStorage getFragmentForString:]), (-[KWQTextStorage
+ initWithFontAttribute:]), (-[KWQTextStorage addLayoutManager:]):
+
+2002-03-14 Richard Williamson <rjw at apple.com>
+
Implemented a progressively cache fragment.
* src/kwq/KWQFontMetrics.mm: (-[KWQSmallLayoutFragment setGlyphRange:]),
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index d0ad12a..7bd0638 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,5 +1,17 @@
2002-03-14 Richard Williamson <rjw at apple.com>
+ Attempted implementation of space optimizations. Disabled for now.
+
+ * src/kwq/KWQFontMetrics.mm: (+[KWQLayoutInfo _dumpLayoutCache:]),
+ (-[KWQLayoutInfo rectForString:]):
+ * src/kwq/KWQMetrics.h:
+ * src/kwq/KWQTextStorage.h:
+ * src/kwq/KWQTextStorage.mm: (-[KWQTextStorage _buildFragmentForString:]),
+ (-[KWQTextStorage getFragmentForString:]), (-[KWQTextStorage
+ initWithFontAttribute:]), (-[KWQTextStorage addLayoutManager:]):
+
+2002-03-14 Richard Williamson <rjw at apple.com>
+
Implemented a progressively cache fragment.
* src/kwq/KWQFontMetrics.mm: (-[KWQSmallLayoutFragment setGlyphRange:]),
diff --git a/WebCore/kwq/KWQFontMetrics.mm b/WebCore/kwq/KWQFontMetrics.mm
index 5c70d7e..7609b69 100644
--- a/WebCore/kwq/KWQFontMetrics.mm
+++ b/WebCore/kwq/KWQFontMetrics.mm
@@ -185,7 +185,7 @@ static NSMutableDictionary *metricsCache = nil;
int i, count;
NSArray *stringKeys;
NSString *string;
- id KWQLayoutFragment>fragment;
+ id <KWQLayoutFragment>fragment;
if (fragCache == nil){
fprintf (stdout, "Fragment cache empty\n");
@@ -274,16 +274,11 @@ static NSMutableDictionary *metricsCache = nil;
- (NSRect)rectForString:(NSString *)string
{
- id <KWQLayoutFragment> cachedFragment, fragment;
+ id <KWQLayoutFragment> cachedFragment;
cachedFragment = [textStorage getFragmentForString: string];
- if (cachedFragment != nil){
- return [cachedFragment boundingRect];
- }
-
- fragment = [textStorage addFragmentForString: string];
- return [fragment boundingRect];
+ return [cachedFragment boundingRect];
}
diff --git a/WebCore/kwq/KWQMetrics.h b/WebCore/kwq/KWQMetrics.h
index 3b499ce..29225ca 100644
--- a/WebCore/kwq/KWQMetrics.h
+++ b/WebCore/kwq/KWQMetrics.h
@@ -63,9 +63,13 @@
@interface KWQSmallLayoutFragment : NSObject <KWQLayoutFragment>
{
+ // Assumes 0,0 boundingRect origin and < UINT16_MAX width and height,
+ // and loss of precision for float to short is irrelevant.
unsigned short width;
unsigned short height;
- unsigned short glyphRangeLength; // Is location always zero? Only need length.
+
+ // Assumes 0 location and < UINT16_MAX length.
+ unsigned short glyphRangeLength;
#ifdef _DEBUG_LAYOUT_FRAGMENT
int accessCount;
#endif
diff --git a/WebCore/kwq/KWQTextStorage.h b/WebCore/kwq/KWQTextStorage.h
index 3a57bc3..4aaa978 100644
--- a/WebCore/kwq/KWQTextStorage.h
+++ b/WebCore/kwq/KWQTextStorage.h
@@ -35,13 +35,16 @@
int stringCapacity;
NSMutableDictionary *fragmentCache;
NSLayoutManager *_layoutManager;
+#ifdef SPACE_OPTIMIZATION
+ id <KWQLayoutFragment> spaceFragment;
+ id <KWQLayoutFragment> expandedFragment;
+#endif
}
- (id)initWithFontAttribute:(NSDictionary *)attrs;
- (void)setAttributes: (NSDictionary *)at;
- (id <KWQLayoutFragment>)getFragmentForString: (NSString *)string;
-- (id <KWQLayoutFragment>)addFragmentForString: (NSString *)string;
- (void)setString: (NSString *)dString;
diff --git a/WebCore/kwq/KWQTextStorage.mm b/WebCore/kwq/KWQTextStorage.mm
index 154ec2c..39b9b18 100644
--- a/WebCore/kwq/KWQTextStorage.mm
+++ b/WebCore/kwq/KWQTextStorage.mm
@@ -45,57 +45,24 @@
@implementation KWQTextStorage
-- (id <KWQLayoutFragment>)getFragmentForString: (NSString *)fragString
-{
- return [fragmentCache objectForKey: fragString];
-}
-
-#ifdef DEBUG_SPACE_OPTIMIZATION
-static int totalMeasurements = 0;
-static int leadingSpace = 0;
-static int trailingSpace = 0;
-#endif
-
-- (id <KWQLayoutFragment>)addFragmentForString: (NSString *)fragString
+- (id <KWQLayoutFragment>)_buildFragmentForString: (NSString *)measureString
{
id <KWQLayoutFragment> fragment;
- bool useLargeFragment = NO;
-
+ NSRange range = NSMakeRange (0, [measureString length]);
+ NSRange glyphRange;
+ NSRect boundingRect;
+
if (fragmentCache == nil)
fragmentCache = [[NSMutableDictionary alloc] init];
-
- int fragStringLength = [fragString length];
-
-#ifdef DEBUG_SPACE_OPTIMIZATION
- totalMeasurements++;
- if (fragStringLength > 1){
- [fragString rangeOfString: @" " options: NSLiteralSearch range: NSMakeRange (0,1)].location = 0;
-
- or
-
- [fragString rangeOfString: @" " options: NSLiteralSearch range: NSMakeRange (fragStringLength,1)].location = fragStringLength
-
- if ([[fragString substringWithRange:NSMakeRange (fragStringLength-1,1)] isEqual: @" "])
- trailingSpace++;
- if ([[fragString substringWithRange:NSMakeRange (0,1)] isEqual: @" "])
- leadingSpace++;
- if (totalMeasurements % 500 == 0){
- fprintf (stdout, "totalMeasurements = %d, trailingSpace = %d, leadingSpace = %d\n", totalMeasurements, trailingSpace, leadingSpace);
- }
- }
-#endif
+ [self setString: measureString];
+ glyphRange = [_layoutManager glyphRangeForCharacterRange:range actualCharacterRange:nil];
+ boundingRect = [_layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: [KWQTextContainer sharedInstance]];
- [self setString: fragString];
+ bool useLargeFragment = NO;
- NSRange range = NSMakeRange (0, fragStringLength);
- NSRange glyphRange = [_layoutManager glyphRangeForCharacterRange:range actualCharacterRange:nil];
- NSRect boundingRect = [_layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: [KWQTextContainer sharedInstance]];
-
- if (boundingRect.origin.x != 0 || boundingRect.origin.y != 0){
- [NSException raise:@"OPTIMIZATION ASSUMPTION VIOLATED" format:@"bounding rect origin not 0,0"];
- }
- if (glyphRange.location != 0 ||
+ if (boundingRect.origin.x != 0 || boundingRect.origin.y != 0 ||
+ glyphRange.location != 0 ||
glyphRange.length > UINT16_MAX ||
boundingRect.size.width > (float)UINT16_MAX ||
boundingRect.size.height > (float)UINT16_MAX){
@@ -109,15 +76,86 @@ static int trailingSpace = 0;
[fragment setGlyphRange: glyphRange];
[fragment setBoundingRect: boundingRect];
- [fragmentCache setObject: fragment forKey: fragString];
+
+ [fragmentCache setObject: fragment forKey: measureString];
[fragment release];
+
+ return fragment;
+}
+
+
+- (id <KWQLayoutFragment>)getFragmentForString: (NSString *)fString
+{
+ id <KWQLayoutFragment> fragment;
+#ifdef SPACE_OPTIMIZATION
+ bool hasLeadingSpace = NO, hasTrailingSpace = NO;
+ const UniChar *clippedStart = 0;
+ unsigned int clippedLength = 0, fragStringLength;
+ CFStringRef clippedString, fragString = (CFStringRef)fString;
+
+ fragStringLength = CFStringGetLength (fragString);
+ if (fragStringLength > 1){
+ const UniChar *internalBuffer = CFStringGetCharactersPtr((CFStringRef)fragString);
+
+ if (internalBuffer){
+ clippedStart = internalBuffer;
+ clippedLength = fragStringLength;
+ if (*internalBuffer == ' '){
+ hasLeadingSpace = YES;
+ clippedStart++;
+ clippedLength--;
+ }
+ if (internalBuffer[fragStringLength-1] == ' '){
+ hasTrailingSpace = YES;
+ clippedLength--;
+ }
+
+ if (hasLeadingSpace || hasTrailingSpace){
+ NSRect boundingRect;
+ NSRange glyphRange;
+
+ clippedString = CFStringCreateWithCharactersNoCopy (kCFAllocatorDefault, clippedStart, clippedLength, kCFAllocatorNull);
+ fragment = [fragmentCache objectForKey: (NSString *)clippedString];
+ if (!fragment)
+ fragment = [self _buildFragmentForString: (NSString *)clippedString];
+ CFRelease (clippedString);
+ boundingRect = [fragment boundingRect];
+ glyphRange = [fragment glyphRange];
+ if (hasLeadingSpace){
+ glyphRange.length++;
+ boundingRect.size.width += [spaceFragment boundingRect].size.width;
+ }
+ if (hasTrailingSpace){
+ glyphRange.length++;
+ boundingRect.size.width += [spaceFragment boundingRect].size.width;
+ }
+ [expandedFragment setBoundingRect: boundingRect];
+ [expandedFragment setGlyphRange: glyphRange];
+
+ return expandedFragment;
+ }
+ }
+ }
+#endif
+
+ fragment = [fragmentCache objectForKey: fString];
+ if (!fragment)
+ fragment = [self _buildFragmentForString: fString];
+
return fragment;
}
+#ifdef DEBUG_SPACE_OPTIMIZATION
+static int totalMeasurements = 0;
+static int leadingSpace = 0;
+static int trailingSpace = 0;
+#endif
+
- (id)initWithFontAttribute:(NSDictionary *)attrs
{
attributes = [attrs retain];
+ expandedFragment = [[KWQLargeLayoutFragment alloc] init];
return self;
}
@@ -136,6 +174,9 @@ static int trailingSpace = 0;
- (void)addLayoutManager:(id)obj {
_layoutManager = [obj retain];
[obj setTextStorage:self];
+#ifdef SPACE_OPTIMIZATION
+ spaceFragment = [self _buildFragmentForString: @" "];
+#endif
}
- (void)removeLayoutManager:(id)obj {
diff --git a/WebCore/src/kwq/KWQFontMetrics.mm b/WebCore/src/kwq/KWQFontMetrics.mm
index 5c70d7e..7609b69 100644
--- a/WebCore/src/kwq/KWQFontMetrics.mm
+++ b/WebCore/src/kwq/KWQFontMetrics.mm
@@ -185,7 +185,7 @@ static NSMutableDictionary *metricsCache = nil;
int i, count;
NSArray *stringKeys;
NSString *string;
- id KWQLayoutFragment>fragment;
+ id <KWQLayoutFragment>fragment;
if (fragCache == nil){
fprintf (stdout, "Fragment cache empty\n");
@@ -274,16 +274,11 @@ static NSMutableDictionary *metricsCache = nil;
- (NSRect)rectForString:(NSString *)string
{
- id <KWQLayoutFragment> cachedFragment, fragment;
+ id <KWQLayoutFragment> cachedFragment;
cachedFragment = [textStorage getFragmentForString: string];
- if (cachedFragment != nil){
- return [cachedFragment boundingRect];
- }
-
- fragment = [textStorage addFragmentForString: string];
- return [fragment boundingRect];
+ return [cachedFragment boundingRect];
}
diff --git a/WebCore/src/kwq/KWQMetrics.h b/WebCore/src/kwq/KWQMetrics.h
index 3b499ce..29225ca 100644
--- a/WebCore/src/kwq/KWQMetrics.h
+++ b/WebCore/src/kwq/KWQMetrics.h
@@ -63,9 +63,13 @@
@interface KWQSmallLayoutFragment : NSObject <KWQLayoutFragment>
{
+ // Assumes 0,0 boundingRect origin and < UINT16_MAX width and height,
+ // and loss of precision for float to short is irrelevant.
unsigned short width;
unsigned short height;
- unsigned short glyphRangeLength; // Is location always zero? Only need length.
+
+ // Assumes 0 location and < UINT16_MAX length.
+ unsigned short glyphRangeLength;
#ifdef _DEBUG_LAYOUT_FRAGMENT
int accessCount;
#endif
diff --git a/WebCore/src/kwq/KWQTextStorage.h b/WebCore/src/kwq/KWQTextStorage.h
index 3a57bc3..4aaa978 100644
--- a/WebCore/src/kwq/KWQTextStorage.h
+++ b/WebCore/src/kwq/KWQTextStorage.h
@@ -35,13 +35,16 @@
int stringCapacity;
NSMutableDictionary *fragmentCache;
NSLayoutManager *_layoutManager;
+#ifdef SPACE_OPTIMIZATION
+ id <KWQLayoutFragment> spaceFragment;
+ id <KWQLayoutFragment> expandedFragment;
+#endif
}
- (id)initWithFontAttribute:(NSDictionary *)attrs;
- (void)setAttributes: (NSDictionary *)at;
- (id <KWQLayoutFragment>)getFragmentForString: (NSString *)string;
-- (id <KWQLayoutFragment>)addFragmentForString: (NSString *)string;
- (void)setString: (NSString *)dString;
diff --git a/WebCore/src/kwq/KWQTextStorage.mm b/WebCore/src/kwq/KWQTextStorage.mm
index 154ec2c..39b9b18 100644
--- a/WebCore/src/kwq/KWQTextStorage.mm
+++ b/WebCore/src/kwq/KWQTextStorage.mm
@@ -45,57 +45,24 @@
@implementation KWQTextStorage
-- (id <KWQLayoutFragment>)getFragmentForString: (NSString *)fragString
-{
- return [fragmentCache objectForKey: fragString];
-}
-
-#ifdef DEBUG_SPACE_OPTIMIZATION
-static int totalMeasurements = 0;
-static int leadingSpace = 0;
-static int trailingSpace = 0;
-#endif
-
-- (id <KWQLayoutFragment>)addFragmentForString: (NSString *)fragString
+- (id <KWQLayoutFragment>)_buildFragmentForString: (NSString *)measureString
{
id <KWQLayoutFragment> fragment;
- bool useLargeFragment = NO;
-
+ NSRange range = NSMakeRange (0, [measureString length]);
+ NSRange glyphRange;
+ NSRect boundingRect;
+
if (fragmentCache == nil)
fragmentCache = [[NSMutableDictionary alloc] init];
-
- int fragStringLength = [fragString length];
-
-#ifdef DEBUG_SPACE_OPTIMIZATION
- totalMeasurements++;
- if (fragStringLength > 1){
- [fragString rangeOfString: @" " options: NSLiteralSearch range: NSMakeRange (0,1)].location = 0;
-
- or
-
- [fragString rangeOfString: @" " options: NSLiteralSearch range: NSMakeRange (fragStringLength,1)].location = fragStringLength
-
- if ([[fragString substringWithRange:NSMakeRange (fragStringLength-1,1)] isEqual: @" "])
- trailingSpace++;
- if ([[fragString substringWithRange:NSMakeRange (0,1)] isEqual: @" "])
- leadingSpace++;
- if (totalMeasurements % 500 == 0){
- fprintf (stdout, "totalMeasurements = %d, trailingSpace = %d, leadingSpace = %d\n", totalMeasurements, trailingSpace, leadingSpace);
- }
- }
-#endif
+ [self setString: measureString];
+ glyphRange = [_layoutManager glyphRangeForCharacterRange:range actualCharacterRange:nil];
+ boundingRect = [_layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: [KWQTextContainer sharedInstance]];
- [self setString: fragString];
+ bool useLargeFragment = NO;
- NSRange range = NSMakeRange (0, fragStringLength);
- NSRange glyphRange = [_layoutManager glyphRangeForCharacterRange:range actualCharacterRange:nil];
- NSRect boundingRect = [_layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: [KWQTextContainer sharedInstance]];
-
- if (boundingRect.origin.x != 0 || boundingRect.origin.y != 0){
- [NSException raise:@"OPTIMIZATION ASSUMPTION VIOLATED" format:@"bounding rect origin not 0,0"];
- }
- if (glyphRange.location != 0 ||
+ if (boundingRect.origin.x != 0 || boundingRect.origin.y != 0 ||
+ glyphRange.location != 0 ||
glyphRange.length > UINT16_MAX ||
boundingRect.size.width > (float)UINT16_MAX ||
boundingRect.size.height > (float)UINT16_MAX){
@@ -109,15 +76,86 @@ static int trailingSpace = 0;
[fragment setGlyphRange: glyphRange];
[fragment setBoundingRect: boundingRect];
- [fragmentCache setObject: fragment forKey: fragString];
+
+ [fragmentCache setObject: fragment forKey: measureString];
[fragment release];
+
+ return fragment;
+}
+
+
+- (id <KWQLayoutFragment>)getFragmentForString: (NSString *)fString
+{
+ id <KWQLayoutFragment> fragment;
+#ifdef SPACE_OPTIMIZATION
+ bool hasLeadingSpace = NO, hasTrailingSpace = NO;
+ const UniChar *clippedStart = 0;
+ unsigned int clippedLength = 0, fragStringLength;
+ CFStringRef clippedString, fragString = (CFStringRef)fString;
+
+ fragStringLength = CFStringGetLength (fragString);
+ if (fragStringLength > 1){
+ const UniChar *internalBuffer = CFStringGetCharactersPtr((CFStringRef)fragString);
+
+ if (internalBuffer){
+ clippedStart = internalBuffer;
+ clippedLength = fragStringLength;
+ if (*internalBuffer == ' '){
+ hasLeadingSpace = YES;
+ clippedStart++;
+ clippedLength--;
+ }
+ if (internalBuffer[fragStringLength-1] == ' '){
+ hasTrailingSpace = YES;
+ clippedLength--;
+ }
+
+ if (hasLeadingSpace || hasTrailingSpace){
+ NSRect boundingRect;
+ NSRange glyphRange;
+
+ clippedString = CFStringCreateWithCharactersNoCopy (kCFAllocatorDefault, clippedStart, clippedLength, kCFAllocatorNull);
+ fragment = [fragmentCache objectForKey: (NSString *)clippedString];
+ if (!fragment)
+ fragment = [self _buildFragmentForString: (NSString *)clippedString];
+ CFRelease (clippedString);
+ boundingRect = [fragment boundingRect];
+ glyphRange = [fragment glyphRange];
+ if (hasLeadingSpace){
+ glyphRange.length++;
+ boundingRect.size.width += [spaceFragment boundingRect].size.width;
+ }
+ if (hasTrailingSpace){
+ glyphRange.length++;
+ boundingRect.size.width += [spaceFragment boundingRect].size.width;
+ }
+ [expandedFragment setBoundingRect: boundingRect];
+ [expandedFragment setGlyphRange: glyphRange];
+
+ return expandedFragment;
+ }
+ }
+ }
+#endif
+
+ fragment = [fragmentCache objectForKey: fString];
+ if (!fragment)
+ fragment = [self _buildFragmentForString: fString];
+
return fragment;
}
+#ifdef DEBUG_SPACE_OPTIMIZATION
+static int totalMeasurements = 0;
+static int leadingSpace = 0;
+static int trailingSpace = 0;
+#endif
+
- (id)initWithFontAttribute:(NSDictionary *)attrs
{
attributes = [attrs retain];
+ expandedFragment = [[KWQLargeLayoutFragment alloc] init];
return self;
}
@@ -136,6 +174,9 @@ static int trailingSpace = 0;
- (void)addLayoutManager:(id)obj {
_layoutManager = [obj retain];
[obj setTextStorage:self];
+#ifdef SPACE_OPTIMIZATION
+ spaceFragment = [self _buildFragmentForString: @" "];
+#endif
}
- (void)removeLayoutManager:(id)obj {
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list