mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-09 18:30:59 +00:00
Performance improvements and bug fixes.
Reviewed by me.
This commit is contained in:
1 parent
ec210c49c5
commit
38fd675f51
8 files changed
+99
-96
No files matched your search
@@ -1,3 +1,6 @@
|
||||
|
||||
makeExportsGlobal();
|
||||
|
||||
var rootNode = new StaticResourceNode("", null, StaticResourceNode.DirectoryType, YES),
|
||||
cwd = FILE.cwd();
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
#define DEPENDENCY_LOGGING 1
|
||||
#define STATIC_RESOURCE_LOGGING 1
|
||||
#define EXECUTION_LOGGING 1
|
||||
+73
-56
@@ -71,7 +71,7 @@ if (code.indexOf("/Users/tolmasky/Desktop/LoadTest/main.j/**/") !== -1)
|
||||
|
||||
Executable.prototype.path = function()
|
||||
{
|
||||
return FILE.cwd();
|
||||
return FILE.join(FILE.cwd(), "(Anonymous)");
|
||||
}
|
||||
|
||||
Executable.prototype.functionParameters = function()
|
||||
@@ -88,6 +88,9 @@ Executable.prototype.functionArguments = function()
|
||||
|
||||
Executable.prototype.execute = function()
|
||||
{
|
||||
#if EXECUTION_LOGGING
|
||||
console.log("EXECUTION: " + this.path());
|
||||
#endif
|
||||
var oldContextBundle = CONTEXT_BUNDLE;
|
||||
|
||||
CONTEXT_BUNDLE = Bundle.bundleContainingPath(this.path());
|
||||
@@ -102,9 +105,8 @@ Executable.prototype.code = function()
|
||||
return this._code;
|
||||
}
|
||||
|
||||
Executable.prototype.fileDependencies = function()
|
||||
Executable.prototype.filePathDependencies = function()
|
||||
{
|
||||
return this._fileDependencies;
|
||||
}
|
||||
|
||||
Executable.prototype.scope = function()
|
||||
@@ -117,14 +119,18 @@ Executable.prototype.hasLoadedFileDependencies = function()
|
||||
return this._fileDependencyLoadStatus === ExecutableLoadedFileDependencies;
|
||||
}
|
||||
var globalIteration = 0;
|
||||
|
||||
Executable.prototype.loadFileDependencies = function()
|
||||
{console.log("load deps for " + this.scope());
|
||||
{
|
||||
#if DEPENDENCY_LOGGING
|
||||
console.log("DEPENDENCY: initiated by " + this.scope());
|
||||
#endif
|
||||
if (this._fileDependencyLoadStatus !== ExecutableUnloadedFileDependencies)
|
||||
return;
|
||||
|
||||
this._fileDependencyLoadStatus = ExecutableLoadingFileDependencies;
|
||||
|
||||
var searchedPaths = { },
|
||||
var searchedPaths = [{ }, { }],
|
||||
foundExecutablePaths = { },
|
||||
fileExecutableSearches = new MutableDictionary(),
|
||||
incompleteFileExecutableSearches = new MutableDictionary();
|
||||
@@ -136,79 +142,90 @@ Executable.prototype.loadFileDependencies = function()
|
||||
if (anExecutable.hasLoadedFileDependencies())
|
||||
return;
|
||||
|
||||
var fileDependencies = anExecutable.fileDependencies(),
|
||||
index = 0,
|
||||
count = fileDependencies.length;
|
||||
var executables = [anExecutable],
|
||||
executableIndex = 0,
|
||||
executableCount = executables.length;
|
||||
|
||||
for (; index < count; ++index)
|
||||
for (; executableIndex < executableCount; ++executableIndex)
|
||||
{
|
||||
var fileDependency = fileDependencies[index],
|
||||
path = fileDependency.path(),
|
||||
isLocal = fileDependency.isLocal();
|
||||
|
||||
if (isLocal)
|
||||
path = FILE.join(anExecutable.path ? FILE.dirname(anExecutable.path()) : FILE.cwd(), path);
|
||||
var executable = executables[executableIndex],
|
||||
cwd = FILE.dirname(executable.path()),
|
||||
fileDependencies = executable.fileDependencies(),
|
||||
fileDependencyIndex = 0,
|
||||
fileDependencyCount = fileDependencies.length;
|
||||
|
||||
if (searchedPaths[path])
|
||||
continue;
|
||||
|
||||
searchedPaths[path] = YES;
|
||||
|
||||
var fileExecutableSearch = new FileExecutableSearch(path, isLocal),
|
||||
fileExecutableSearchUID = fileExecutableSearch.UID();
|
||||
|
||||
if (fileExecutableSearches.containsKey(fileExecutableSearchUID))
|
||||
continue;
|
||||
|
||||
fileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch);
|
||||
|
||||
if (fileExecutableSearch.isComplete())
|
||||
searchForFileDependencies(fileExecutableSearch.result());
|
||||
|
||||
else
|
||||
for (; fileDependencyIndex < fileDependencyCount; ++fileDependencyIndex)
|
||||
{
|
||||
incompleteFileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch);
|
||||
|
||||
fileExecutableSearch.addEventListener("complete", function(/*Event*/ anEvent)
|
||||
var fileDependency = fileDependencies[fileDependencyIndex],
|
||||
isLocal = fileDependency.isLocal(),
|
||||
path = importablePath(fileDependency.path(), isLocal, cwd);
|
||||
|
||||
if (searchedPaths[isLocal ? 1 : 0][path])
|
||||
continue;
|
||||
|
||||
searchedPaths[isLocal ? 1 : 0][path] = YES;
|
||||
|
||||
var fileExecutableSearch = new FileExecutableSearch(path, isLocal),
|
||||
fileExecutableSearchUID = fileExecutableSearch.UID();
|
||||
|
||||
if (fileExecutableSearches.containsKey(fileExecutableSearchUID))
|
||||
continue;
|
||||
|
||||
fileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch);
|
||||
|
||||
if (fileExecutableSearch.isComplete())
|
||||
{
|
||||
var fileExecutableSearch = anEvent.fileExecutableSearch,
|
||||
fileExecutable = fileExecutableSearch.result();
|
||||
//console.log("DONE FOR: " + search.UID() + " " + search.resultantFilePath());
|
||||
foundExecutablePaths[fileExecutable.path()] = fileExecutable;
|
||||
incompleteFileExecutableSearches.removeValueForKey(fileExecutableSearch.UID());
|
||||
|
||||
searchForFileDependencies(fileExecutableSearch.result());
|
||||
});
|
||||
var newFileExecutable = fileExecutableSearch.result();
|
||||
|
||||
foundExecutablePaths[newFileExecutable.path()] = executable;
|
||||
executables.push(newFileExecutable);
|
||||
++executableCount;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
incompleteFileExecutableSearches.setValueForKey(fileExecutableSearchUID, fileExecutableSearch);
|
||||
|
||||
fileExecutableSearch.addEventListener("complete", function( anEvent)
|
||||
{
|
||||
var fileExecutableSearch = anEvent.fileExecutableSearch,
|
||||
fileExecutable = fileExecutableSearch.result();
|
||||
|
||||
foundExecutablePaths[fileExecutable.path()] = fileExecutable;
|
||||
incompleteFileExecutableSearches.removeValueForKey(fileExecutableSearch.UID());
|
||||
|
||||
searchForFileDependencies(fileExecutable);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (incompleteFileExecutableSearches.count() > 0)
|
||||
{
|
||||
if (globalIteration++ > 200)
|
||||
throw "too many.";
|
||||
console.log("keep going");
|
||||
var keys = incompleteFileExecutableSearches.keys(),
|
||||
index = 0,
|
||||
count = keys.length;
|
||||
for(; index < count; ++index)
|
||||
console.log(":::"+keys[index] + " " + incompleteFileExecutableSearches.valueForKey(keys[index])._path);
|
||||
#if !DEPENDENCY_LOGGING
|
||||
return;
|
||||
}
|
||||
console.log("what?");
|
||||
#else
|
||||
{
|
||||
console.log("DEPENDENCY: more dependencies: ");
|
||||
console.log(incompleteFileExecutableSearches.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("DEPENDENCY: Ended");
|
||||
#end
|
||||
var fileExecutablesNeedingEventDispatch = [];
|
||||
|
||||
for (var executablePath in foundExecutablePaths)
|
||||
if (hasOwnProperty.apply(foundExecutablePaths, [executablePath]))
|
||||
{
|
||||
var fileExecutable = new FileExecutable(executablePath);
|
||||
console.log("no go for... " + fileExecutable.path());
|
||||
//console.log("no go for... " + fileExecutable.path());
|
||||
if (fileExecutable.hasLoadedFileDependencies())
|
||||
continue;
|
||||
|
||||
fileExecutablesNeedingEventDispatch.push(fileExecutable);
|
||||
fileExecutable._fileDependencyLoadStatus = FileExecutableLoadedDependencies;
|
||||
}
|
||||
|
||||
|
||||
var index = 0,
|
||||
count = fileExecutablesNeedingEventDispatch.length;
|
||||
|
||||
|
||||
@@ -71,42 +71,6 @@ FileExecutable.prototype.hasExecuted = function()
|
||||
return this._hasExecuted;
|
||||
}
|
||||
|
||||
function importFile(/*String*/ aPath, /*BOOL*/ isLocal, /*Function*/ aCallback)
|
||||
{
|
||||
aPath = FILE.normal(aPath);
|
||||
|
||||
if (isLocal)
|
||||
aPath = FILE.absolute(aPath);
|
||||
|
||||
var search = new FileExecutableSearch(aPath, isLocal);
|
||||
|
||||
function searchComplete(/*FileExecutableSearch*/ aFileExecutableSearch)
|
||||
{console.log("search complete: " + aFileExecutableSearch);
|
||||
var fileExecutable = aFileExecutableSearch.result();
|
||||
|
||||
if (!fileExecutable.hasLoadedFileDependencies())
|
||||
{
|
||||
fileExecutable.loadFileDependencies();
|
||||
|
||||
fileExecutable.addEventListener("dependenciesload", function()
|
||||
{
|
||||
executeFile(aPath, isLocal);
|
||||
});
|
||||
}
|
||||
else
|
||||
executeFile(aPath, isLocal);
|
||||
}
|
||||
|
||||
if (search.isComplete())
|
||||
searchComplete(search);
|
||||
else
|
||||
search.addEventListener("complete", function(/*Event*/ anEvent)
|
||||
{
|
||||
console.log("completed...");
|
||||
searchComplete(anEvent.fileExecutableSearch);
|
||||
});
|
||||
}
|
||||
|
||||
function decompile(/*String*/ aString, /*String*/ aPath)
|
||||
{
|
||||
var stream = new MarkedStream(aString);
|
||||
|
||||
@@ -98,3 +98,10 @@ FileExecutableSearch.prototype.removeEventListener = function(/*String*/ anEvent
|
||||
{
|
||||
this._eventDispatcher.removeEventListener(anEventName, aListener);
|
||||
}
|
||||
|
||||
#if DEPENDENCY_LOGGING
|
||||
FileExecutableSearch.prototype.toString = function()
|
||||
{
|
||||
return "<FileExecutableSearch: " + this.path() + ">";
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
#include "DebugOptions.js"
|
||||
#include "Constants.js"
|
||||
#include "EventDispatcher.js"
|
||||
#include "HTTPRequest.js"
|
||||
|
||||
@@ -285,8 +285,6 @@ function class_getMethodImplementation(/*Class*/ aClass, /*SEL*/ aSelector)
|
||||
var GLOBAL_NAMESPACE = global,
|
||||
REGISTERED_CLASSES = { };
|
||||
|
||||
var CONTEXT_BUNDLE = nil;
|
||||
|
||||
function objj_allocateClassPair(/*Class*/ superclass, /*String*/ aName)
|
||||
{
|
||||
var classObject = new objj_class(),
|
||||
@@ -331,12 +329,14 @@ function objj_allocateClassPair(/*Class*/ superclass, /*String*/ aName)
|
||||
return classObject;
|
||||
}
|
||||
|
||||
var CONTEXT_BUNDLE = nil;
|
||||
|
||||
function objj_registerClassPair(/*Class*/ aClass)
|
||||
{
|
||||
GLOBAL_NAMESPACE[aClass.name] = aClass;
|
||||
REGISTERED_CLASSES[aClass.name] = aClass;
|
||||
|
||||
addClassToBundle(CONTEXT_BUNDLE, aClass);
|
||||
addClassToBundle(aClass, CONTEXT_BUNDLE);
|
||||
}
|
||||
|
||||
// Instantiating Classes
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
|
||||
function makeExportsGlobal()
|
||||
{
|
||||
for (var exportName in exports)
|
||||
if (hasOwnProperty.apply(exports, [exportName]))
|
||||
global[exportName] = exports[exportName];
|
||||
}
|
||||
|
||||
var cachedExportedNames = [],
|
||||
cachedExportedValues = [];
|
||||
|
||||
@@ -66,7 +73,7 @@ function fileExecuterForPath(/*String*/ referencePath)
|
||||
|
||||
if (0 && !fileExecutable.hasLoadedFileDependencies())
|
||||
throw "No executable loaded for file at path " + aPath;
|
||||
console.log("executing " + aPath);
|
||||
//console.log("executing " + aPath);
|
||||
//console.log(aPath + " " + (isLocal ? 1 : 0) + " " + executable.isLoaded() + " " + executable.hasLoadedDependencies());
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user