summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKris Maglione <kris@vimperator.org>2010-06-10 01:16:36 -0400
committerKris Maglione <kris@vimperator.org>2010-06-10 01:16:36 -0400
commita14e5127df0551806978dcbe181e9cbc2dd14363 (patch)
tree5f51d8b566aa6433501d722ffb55947893278383
parenta6f90714e4320d057607d105b6acbf6509ba508c (diff)
downloadpentadactyl-a14e5127df0551806978dcbe181e9cbc2dd14363.tar.gz
Lazy load help files. Store command names in a map.
--HG-- branch : testing
-rw-r--r--common/content/commands.js15
-rw-r--r--common/content/io.js3
-rw-r--r--common/content/liberator.js149
3 files changed, 90 insertions, 77 deletions
diff --git a/common/content/commands.js b/common/content/commands.js
index ab9cebbb..8b59730a 100644
--- a/common/content/commands.js
+++ b/common/content/commands.js
@@ -73,9 +73,9 @@ const Command = Class("Command", {
modifiers = modifiers || {};
let self = this;
- function exec(args) {
+ function exec(command) {
// FIXME: Move to parseCommand?
- args = self.parseArgs(args);
+ args = self.parseArgs(command);
if (!args)
return;
args.count = count;
@@ -237,6 +237,7 @@ const ArgType = Struct("description", "parse");
const Commands = Module("commands", {
init: function () {
this._exCommands = [];
+ this._exMap = {};
},
// FIXME: remove later, when our option handler is better
@@ -304,7 +305,7 @@ const Commands = Module("commands", {
repeat: null,
_addCommand: function (command, replace) {
- if (this._exCommands.some(function (c) c.hasName(command.name))) {
+ if (command.name in this._exMap) {
if (command.user && replace)
commands.removeUserCommand(command.name);
else {
@@ -314,6 +315,8 @@ const Commands = Module("commands", {
}
this._exCommands.push(command);
+ for(let [,name] in Iterator(command.names))
+ this._exMap[name] = command;
return true;
},
@@ -387,7 +390,7 @@ const Commands = Module("commands", {
* @returns {Command}
*/
get: function (name) {
- return this._exCommands.filter(function (cmd) cmd.hasName(name))[0] || null;
+ return this._exMap[name] || this._exCommands.filter(function (cmd) cmd.hasName(name))[0] || null;
},
/**
@@ -762,6 +765,10 @@ const Commands = Module("commands", {
* any of the command's names.
*/
removeUserCommand: function (name) {
+ for(let [,cmd] in Iterator(this._exCommands))
+ if(cmd.user && cmd.hasName(name))
+ for(let [,name] in Iterator(cmd.names))
+ delete this._exMap[name];
this._exCommands = this._exCommands.filter(function (cmd) !(cmd.user && cmd.hasName(name)));
},
diff --git a/common/content/io.js b/common/content/io.js
index 2aa3f9e8..5b599215 100644
--- a/common/content/io.js
+++ b/common/content/io.js
@@ -597,6 +597,8 @@ lookup:
*/
source: function (filename, silent) {
let wasSourcing = this.sourcing;
+ liberator.dump("sourcing " + filename);
+ let time = Date.now();
try {
var file = File(filename);
this.sourcing = {
@@ -715,6 +717,7 @@ lookup:
liberator.echoerr(message);
}
finally {
+ liberator.dump("done sourcing " + filename + ": " + (Date.now() - time) + "ms");
this.sourcing = wasSourcing;
}
},
diff --git a/common/content/liberator.js b/common/content/liberator.js
index a4617b4c..6b2bc0a2 100644
--- a/common/content/liberator.js
+++ b/common/content/liberator.js
@@ -544,85 +544,88 @@ const Liberator = Module("liberator", {
* Initialize the help system.
*/
initHelp: function () {
- let namespaces = [config.name.toLowerCase(), "liberator"];
- services.get("liberator:").init({});
-
- let tagMap = services.get("liberator:").HELP_TAGS;
- let fileMap = services.get("liberator:").FILE_MAP;
- let overlayMap = services.get("liberator:").OVERLAY_MAP;
-
- // Left as an XPCOM instantiation so it can easilly be moved
- // into XPCOM code.
- function XSLTProcessor(sheet) {
- let xslt = Cc["@mozilla.org/document-transformer;1?type=xslt"].createInstance(Ci.nsIXSLTProcessor);
- xslt.importStylesheet(util.httpGet(sheet).responseXML);
- return xslt;
- }
+ if(!this.helpInitialized) {
+ let namespaces = [config.name.toLowerCase(), "liberator"];
+ services.get("liberator:").init({});
+
+ let tagMap = services.get("liberator:").HELP_TAGS;
+ let fileMap = services.get("liberator:").FILE_MAP;
+ let overlayMap = services.get("liberator:").OVERLAY_MAP;
+
+ // Left as an XPCOM instantiation so it can easilly be moved
+ // into XPCOM code.
+ function XSLTProcessor(sheet) {
+ let xslt = Cc["@mozilla.org/document-transformer;1?type=xslt"].createInstance(Ci.nsIXSLTProcessor);
+ xslt.importStylesheet(util.httpGet(sheet).responseXML);
+ return xslt;
+ }
- // Find help and overlay files with the given name.
- function findHelpFile(file) {
- let result = [];
- for (let [, namespace] in Iterator(namespaces)) {
- let url = ["chrome://", namespace, "/locale/", file, ".xml"].join("");
- let res = util.httpGet(url);
- if (res) {
- if (res.responseXML.documentElement.localName == "document")
- fileMap[file] = url;
- if (res.responseXML.documentElement.localName == "overlay")
- overlayMap[file] = url;
- result.push(res.responseXML);
+ // Find help and overlay files with the given name.
+ function findHelpFile(file) {
+ let result = [];
+ for (let [, namespace] in Iterator(namespaces)) {
+ let url = ["chrome://", namespace, "/locale/", file, ".xml"].join("");
+ let res = util.httpGet(url);
+ if (res) {
+ if (res.responseXML.documentElement.localName == "document")
+ fileMap[file] = url;
+ if (res.responseXML.documentElement.localName == "overlay")
+ overlayMap[file] = url;
+ result.push(res.responseXML);
+ }
}
+ return result;
+ }
+ // Find the tags in the document.
+ function addTags(file, doc) {
+ doc = XSLT.transformToDocument(doc);
+ for (let elem in util.evaluateXPath("//xhtml:a/@id", doc))
+ tagMap[elem.value] = file;
}
- return result;
- }
- // Find the tags in the document.
- function addTags(file, doc) {
- doc = XSLT.transformToDocument(doc);
- for (let elem in util.evaluateXPath("//xhtml:a/@id", doc))
- tagMap[elem.value] = file;
- }
- const XSLT = XSLTProcessor("chrome://liberator/content/help-single.xsl");
+ const XSLT = XSLTProcessor("chrome://liberator/content/help-single.xsl");
- // Scrape the list of help files from all.xml
- // Always process main and overlay files, since XSLTProcessor and
- // XMLHttpRequest don't allow access to chrome documents.
- tagMap.all = "all";
- let files = findHelpFile("all").map(function (doc)
- [f.value for (f in util.evaluateXPath(
- "//liberator:include/@href", doc))]);
+ // Scrape the list of help files from all.xml
+ // Always process main and overlay files, since XSLTProcessor and
+ // XMLHttpRequest don't allow access to chrome documents.
+ tagMap.all = "all";
+ let files = findHelpFile("all").map(function (doc)
+ [f.value for (f in util.evaluateXPath(
+ "//liberator:include/@href", doc))]);
- // Scrape the tags from the rest of the help files.
- util.Array.flatten(files).forEach(function (file) {
- findHelpFile(file).forEach(function (doc) {
- addTags(file, doc);
+ // Scrape the tags from the rest of the help files.
+ util.Array.flatten(files).forEach(function (file) {
+ findHelpFile(file).forEach(function (doc) {
+ addTags(file, doc);
+ });
});
- });
- // Process plugin help entries.
- XML.ignoreWhiteSpace = false;
- XML.prettyPrinting = false;
- XML.prettyPrinting = true; // Should be false, but ignoreWhiteSpace=false doesn't work correctly. This is the lesser evil.
- XML.prettyIndent = 4;
-
- let body = XML();
- for (let [, context] in Iterator(plugins.contexts))
- if (context.INFO instanceof XML)
- body += <h2 xmlns={NS.uri} tag={context.INFO.@name + '-plugin'}>{context.INFO.@summary}</h2> +
- context.INFO;
-
- let help = '<?xml version="1.0"?>\n' +
- '<?xml-stylesheet type="text/xsl" href="chrome://liberator/content/help.xsl"?>\n' +
- '<!DOCTYPE document SYSTEM "chrome://liberator/content/liberator.dtd">' +
- <document xmlns={NS}
- name="plugins" title={config.name + " Plugins"}>
- <h1 tag="using-plugins">Using Plugins</h1>
-
- {body}
- </document>.toXMLString();
- fileMap["plugins"] = function () ['text/xml;charset=UTF-8', help];
-
- addTags("plugins", util.httpGet("liberator://help/plugins").responseXML);
+ // Process plugin help entries.
+ XML.ignoreWhiteSpace = false;
+ XML.prettyPrinting = false;
+ XML.prettyPrinting = true; // Should be false, but ignoreWhiteSpace=false doesn't work correctly. This is the lesser evil.
+ XML.prettyIndent = 4;
+
+ let body = XML();
+ for (let [, context] in Iterator(plugins.contexts))
+ if (context.INFO instanceof XML)
+ body += <h2 xmlns={NS.uri} tag={context.INFO.@name + '-plugin'}>{context.INFO.@summary}</h2> +
+ context.INFO;
+
+ let help = '<?xml version="1.0"?>\n' +
+ '<?xml-stylesheet type="text/xsl" href="chrome://liberator/content/help.xsl"?>\n' +
+ '<!DOCTYPE document SYSTEM "chrome://liberator/content/liberator.dtd">' +
+ <document xmlns={NS}
+ name="plugins" title={config.name + " Plugins"}>
+ <h1 tag="using-plugins">Using Plugins</h1>
+
+ {body}
+ </document>.toXMLString();
+ fileMap["plugins"] = function () ['text/xml;charset=UTF-8', help];
+
+ addTags("plugins", util.httpGet("liberator://help/plugins").responseXML);
+ this.helpInitialized = true;
+ }
},
/**
@@ -634,6 +637,7 @@ const Liberator = Module("liberator", {
* @returns {string}
*/
help: function (topic, unchunked) {
+ liberator.initHelp();
if (!topic) {
let helpFile = unchunked ? "all" : options["helpfile"];
if (helpFile in services.get("liberator:").FILE_MAP)
@@ -1717,6 +1721,7 @@ const Liberator = Module("liberator", {
};
completion.help = function help(context, unchunked) {
+ liberator.initHelp();
context.title = ["Help"];
context.anchored = false;
context.completions = services.get("liberator:").HELP_TAGS;
@@ -1820,8 +1825,6 @@ const Liberator = Module("liberator", {
if (options["loadplugins"])
liberator.loadPlugins();
- liberator.initHelp();
-
// after sourcing the initialization files, this function will set
// all gui options to their default values, if they have not been
// set before by any RC file