Commit 8636c6f1 authored by darin's avatar darin
Browse files

WebFoundation:

        Reviewed by Maciej.

	- fixed most likely cause of 3125565 -- 2% regression running the PLT for uncached loads

        * Misc.subproj/WebNSUserDefaultsExtras.m:
        (+[NSUserDefaults _web_defaultsDidChange]): Added. Clears out cache when defaults change.
        (+[NSUserDefaults _web_addDefaultsChangeObserver]): Added. Sets up the above to run at the right time.
        (+[NSUserDefaults _web_acceptLanguageHeaderForPreferredLanguages]): Changed to cache the result in a
	global and regenerate it when the global is cleared.
        (+[NSUserDefaults _web_preferredLanguageCode]): Ditto.

WebKit:

        Reviewed by Maciej.

        - fixed most likely cause of 3125565 -- 2% regression running the PLT for uncached loads

        Don't recompute the user agent when it doesn't change. It almost never changes.

        * WebView.subproj/WebController.m:
        (-[WebController initWithView:controllerSetName:]): Add observer so we know when defaults change.
        (-[WebController dealloc]): Remove observer.
        (-[WebController setApplicationNameForUserAgent:]): Clear out computed user agent to force it
	to be recomputed later.
        (-[WebController applicationNameForUserAgent]): Just retain since we copied when we stored it
	so we know it's not mutable.
        (-[WebController customUserAgent]): Ditto.
        (-[WebController userAgentForURL:]): Use the cached user agent if it's good. Otherwise compute
	and cache the user agent string. This means that we will almost never recompute it.

        * WebView.subproj/WebControllerPrivate.h: Add userAgent field to cache in.
        * WebView.subproj/WebControllerPrivate.m:
        (-[WebControllerPrivate dealloc]): Release userAgent.
        (-[WebController _defaultsDidChange]): Release and nil userAgent.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3019 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7884603b
2002-12-12 Darin Adler <darin@apple.com>
Reviewed by Maciej.
- fixed most likely cause of 3125565 -- 2% regression running the PLT for uncached loads
Don't recompute the user agent when it doesn't change. It almost never changes.
* WebView.subproj/WebController.m:
(-[WebController initWithView:controllerSetName:]): Add observer so we know when defaults change.
(-[WebController dealloc]): Remove observer.
(-[WebController setApplicationNameForUserAgent:]): Clear out computed user agent to force it
to be recomputed later.
(-[WebController applicationNameForUserAgent]): Just retain since we copied when we stored it
so we know it's not mutable.
(-[WebController customUserAgent]): Ditto.
(-[WebController userAgentForURL:]): Use the cached user agent if it's good. Otherwise compute
and cache the user agent string. This means that we will almost never recompute it.
* WebView.subproj/WebControllerPrivate.h: Add userAgent field to cache in.
* WebView.subproj/WebControllerPrivate.m:
(-[WebControllerPrivate dealloc]): Release userAgent.
(-[WebController _defaultsDidChange]): Release and nil userAgent.
2002-12-12 Darin Adler <darin@apple.com>
Reviewed by Maciej.
......
......@@ -62,6 +62,11 @@ @implementation WebController
[self setUsesBackForwardList: YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_defaultsDidChange)
name:NSUserDefaultsDidChangeNotification
object:[NSUserDefaults standardUserDefaults]];
++WebControllerCount;
return self;
......@@ -75,6 +80,8 @@ - (void)dealloc
--WebControllerCount;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_private release];
[super dealloc];
}
......@@ -307,11 +314,13 @@ - (void)setApplicationNameForUserAgent:(NSString *)applicationName
NSString *name = [applicationName copy];
[_private->applicationNameForUserAgent release];
_private->applicationNameForUserAgent = name;
[_private->userAgent release];
_private->userAgent = nil;
}
- (NSString *)applicationNameForUserAgent
{
return [[_private->applicationNameForUserAgent copy] autorelease];
return [[_private->applicationNameForUserAgent retain] autorelease];
}
- (void)setCustomUserAgent:(NSString *)userAgentString
......@@ -340,15 +349,17 @@ - (NSString *)customUserAgent
ERROR("must not ask for customUserAgent is hasCustomUserAgent is NO");
}
return [[_private->userAgentOverride copy] autorelease];
return [[_private->userAgentOverride retain] autorelease];
}
// Get the appropriate user-agent string for a particular URL.
- (NSString *)userAgentForURL:(NSURL *)URL
{
NSString *result = [[_private->userAgentOverride copy] autorelease];
if (result) {
return result;
if (_private->userAgentOverride) {
return [[_private->userAgentOverride retain] autorelease];
}
if (_private->userAgent) {
return [[_private->userAgent retain] autorelease];
}
// Note that we currently don't look at the URL.
......@@ -362,12 +373,17 @@ - (NSString *)userAgentForURL:(NSURL *)URL
objectForInfoDictionaryKey:(id)kCFBundleVersionKey];
NSString *applicationName = _private->applicationNameForUserAgent;
NSString *userAgent;
if ([applicationName length]) {
return [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@ %@",
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@ %@",
language, sourceVersion, applicationName];
} else {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@",
language, sourceVersion];
}
return [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@",
language, sourceVersion];
_private->userAgent = [userAgent retain];
return userAgent;
}
- (BOOL)supportsTextEncoding
......@@ -464,5 +480,4 @@ - (void)pluginFailedWithError:(WebPluginError *)error dataSource:(WebDataSource
{
}
@end
......@@ -30,6 +30,7 @@
NSString *applicationNameForUserAgent;
NSString *userAgentOverride;
NSString *userAgent;
BOOL defersCallbacks;
......
......@@ -64,6 +64,7 @@ - (void)dealloc
[backForwardList release];
[applicationNameForUserAgent release];
[userAgentOverride release];
[userAgent release];
[controllerSetName release];
[topLevelFrameName release];
......@@ -330,4 +331,10 @@ - (void)_mouseDidMoveOverElement:(NSDictionary *)dictionary modifierFlags:(unsig
_private->lastElementWasNonNil = dictionary != nil;
}
- (void)_defaultsDidChange
{
[_private->userAgent release];
_private->userAgent = nil;
}
@end
......@@ -62,6 +62,11 @@ @implementation WebController
[self setUsesBackForwardList: YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_defaultsDidChange)
name:NSUserDefaultsDidChangeNotification
object:[NSUserDefaults standardUserDefaults]];
++WebControllerCount;
return self;
......@@ -75,6 +80,8 @@ - (void)dealloc
--WebControllerCount;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_private release];
[super dealloc];
}
......@@ -307,11 +314,13 @@ - (void)setApplicationNameForUserAgent:(NSString *)applicationName
NSString *name = [applicationName copy];
[_private->applicationNameForUserAgent release];
_private->applicationNameForUserAgent = name;
[_private->userAgent release];
_private->userAgent = nil;
}
- (NSString *)applicationNameForUserAgent
{
return [[_private->applicationNameForUserAgent copy] autorelease];
return [[_private->applicationNameForUserAgent retain] autorelease];
}
- (void)setCustomUserAgent:(NSString *)userAgentString
......@@ -340,15 +349,17 @@ - (NSString *)customUserAgent
ERROR("must not ask for customUserAgent is hasCustomUserAgent is NO");
}
return [[_private->userAgentOverride copy] autorelease];
return [[_private->userAgentOverride retain] autorelease];
}
// Get the appropriate user-agent string for a particular URL.
- (NSString *)userAgentForURL:(NSURL *)URL
{
NSString *result = [[_private->userAgentOverride copy] autorelease];
if (result) {
return result;
if (_private->userAgentOverride) {
return [[_private->userAgentOverride retain] autorelease];
}
if (_private->userAgent) {
return [[_private->userAgent retain] autorelease];
}
// Note that we currently don't look at the URL.
......@@ -362,12 +373,17 @@ - (NSString *)userAgentForURL:(NSURL *)URL
objectForInfoDictionaryKey:(id)kCFBundleVersionKey];
NSString *applicationName = _private->applicationNameForUserAgent;
NSString *userAgent;
if ([applicationName length]) {
return [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@ %@",
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@ %@",
language, sourceVersion, applicationName];
} else {
userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@",
language, sourceVersion];
}
return [NSString stringWithFormat:@"Mozilla/5.0 (Macintosh; U; PPC; %@) WebKit/%@",
language, sourceVersion];
_private->userAgent = [userAgent retain];
return userAgent;
}
- (BOOL)supportsTextEncoding
......@@ -464,5 +480,4 @@ - (void)pluginFailedWithError:(WebPluginError *)error dataSource:(WebDataSource
{
}
@end
......@@ -30,6 +30,7 @@
NSString *applicationNameForUserAgent;
NSString *userAgentOverride;
NSString *userAgent;
BOOL defersCallbacks;
......
......@@ -64,6 +64,7 @@ - (void)dealloc
[backForwardList release];
[applicationNameForUserAgent release];
[userAgentOverride release];
[userAgent release];
[controllerSetName release];
[topLevelFrameName release];
......@@ -330,4 +331,10 @@ - (void)_mouseDidMoveOverElement:(NSDictionary *)dictionary modifierFlags:(unsig
_private->lastElementWasNonNil = dictionary != nil;
}
- (void)_defaultsDidChange
{
[_private->userAgent release];
_private->userAgent = nil;
}
@end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment