A few performance improvements in Objective-J loading.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I committed 2010-03-06 16:01:03 -08:00
1 parent 89bd5f5b93
commit 981c184c20
2 files changed
+41 -25

No files matched your search

+31 -20
View File
@@ -151,6 +151,8 @@ function CFURLGetParts(/*CFURL*/ aURL)
return parts;
}
#define PARTS(aURL) ((aURL)._parts || CFURLGetParts(aURL))
GLOBAL(CFURL) = function(/*CFURL|String*/ aURL, /*CFURL*/ aBaseURL)
{
aURL = aURL || "";
@@ -256,9 +258,10 @@ function resolveURL(aURL)
if (!baseURL)
return aURL;
var parts = CFURLGetParts(aURL),
var parts = PARTS(aURL),
resolvedParts,
baseParts = CFURLGetParts(baseURL.absoluteURL());
absoluteBaseURL = baseURL.absoluteURL(),
baseParts = PARTS(absoluteBaseURL);
if (parts.scheme || parts.authority)
resolvedParts = parts;
@@ -397,7 +400,7 @@ CFURL.prototype.standardizedURL = function()
{
if (this._standardizedURL === undefined)
{
var parts = CFURLGetParts(this),
var parts = PARTS(this),
pathComponents = parts.pathComponents,
standardizedPathComponents = pathComponents.slice();
@@ -449,7 +452,7 @@ CFURL.prototype.string = function()
CFURL.prototype.authority = function()
{
var authority = CFURLGetParts(this).authority;
var authority = PARTS(this).authority;
if (authority)
return authority;
@@ -461,17 +464,25 @@ CFURL.prototype.authority = function()
CFURL.prototype.hasDirectoryPath = function()
{
var path = this.path();
var hasDirectoryPath = this._hasDirectoryPath;
if (!path)
return NO;
if (hasDirectoryPath === undefined)
{
var path = this.path();
if (path.charAt(path.length - 1) === "/")
return YES;
if (!path)
return NO;
var lastPathComponent = this.lastPathComponent();
if (path.charAt(path.length - 1) === "/")
return YES;
return lastPathComponent === "." || lastPathComponent === "..";
var lastPathComponent = this.lastPathComponent();
hasDirectoryPath = lastPathComponent === "." || lastPathComponent === "..";
this._hasDirectoryPath = hasDirectoryPath;
}
return this._hasDirectoryPath;
}
CFURL.prototype.hostName = function()
@@ -481,7 +492,7 @@ CFURL.prototype.hostName = function()
CFURL.prototype.fragment = function()
{
return CFURLGetParts(this).fragment;
return PARTS(this).fragment;
}
CFURL.prototype.lastPathComponent = function()
@@ -497,12 +508,12 @@ CFURL.prototype.lastPathComponent = function()
CFURL.prototype.path = function()
{
return CFURLGetParts(this).path;
return PARTS(this).path;
}
CFURL.prototype.pathComponents = function()
{
return CFURLGetParts(this).pathComponents;
return PARTS(this).pathComponents;
}
CFURL.prototype.pathExtension = function()
@@ -521,12 +532,12 @@ CFURL.prototype.pathExtension = function()
CFURL.prototype.queryString = function()
{
return CFURLGetParts(this).queryString;
return PARTS(this).queryString;
}
CFURL.prototype.scheme = function()
{
var scheme = CFURLGetParts(this).scheme;
var scheme = PARTS(this).scheme;
if (scheme)
return scheme;
@@ -538,22 +549,22 @@ CFURL.prototype.scheme = function()
CFURL.prototype.user = function()
{
return CFURLGetParts(this).user;
return PARTS(this).user;
}
CFURL.prototype.password = function()
{
return CFURLGetParts(this).password;
return PARTS(this).password;
}
CFURL.prototype.portNumber = function()
{
return CFURLGetParts(this).portNumber;
return PARTS(this).portNumber;
}
CFURL.prototype.domain = function()
{
return CFURLGetParts(this).domain;
return PARTS(this).domain;
}
CFURL.prototype.baseURL = function()
+10 -5
View File
@@ -144,30 +144,35 @@ Executable.prototype.setCode = function(code)
{
this._code = code;
var parameters = this.functionParameters().join(","),
absoluteString = this.URL().absoluteString();
var parameters = this.functionParameters().join(",");
#if COMMONJS
if (typeof system !== "undefined" && system.engine === "rhino")
{
code = "function(" + parameters + "){" + code + "/**/\n}";
this._function = Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(window, code, absoluteString, 0, NULL);
this._function = Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(window, code, this.URL().absoluteString(), 0, NULL);
}
else
{
#endif
#if DEBUG
// "//@ sourceURL=" at the end lets us name our eval'd files for debuggers, etc.
// * WebKit: http://pmuellr.blogspot.com/2009/06/debugger-friendly.html
// * Firebug: http://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/
//if (YES) {
code += "/**/\n//@ sourceURL=" + "hello" + absoluteString;
this._function = new Function(parameters, code);
var absoluteString = this.URL().absoluteString();
code += "/**/\n//@ sourceURL=" + absoluteString;
//} else {
// // Firebug only does it for "eval()", not "new Function()". Ugh. Slower.
// var functionText = "(function(){"+GET_CODE(aFragment)+"/**/\n})\n//@ sourceURL="+GET_FILE(aFragment).path;
// compiled = eval(functionText);
//}
#endif
this._function = new Function(parameters, code);
#if DEBUG
this._function.displayName = absoluteString;
#endif
#if COMMONJS
}
#endif