From 911470e0a76c333a4ad89430dddef089f506a80d Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 20 Dec 2008 13:30:08 -0500 Subject: [PATCH] Speed up file completion a bit, with sorting off. Sort directories first, which slows it down with sorting on. --- common/content/completion.js | 53 ++++++++++++++++++------------------ common/content/io.js | 3 +- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/common/content/completion.js b/common/content/completion.js index 7eee6591..f05dd141 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -327,7 +327,7 @@ CompletionContext.prototype = { this.itemCache = {}; this.cache.offset = this.offset; if (!this.itemCache[this.key]) - this.itemCache[this.key] = this._generate.call(this); + this.itemCache[this.key] = this._generate.call(this) || []; return this.itemCache[this.key]; }, set generate(arg) @@ -1384,7 +1384,7 @@ function Completion() //{{{ io.getRuntimeDirectories("colors").forEach(function (dir) { context.fork(dir.path, 0, null, function (context) { context.filter = dir.path + io.pathSeparator + context.filter; - completion.file(context, true); + completion.file(context); context.title = ["Color Scheme"]; context.quote = ["", function (text) text.replace(/\.vimp$/, ""), ""]; }); @@ -1404,10 +1404,10 @@ function Completion() //{{{ context.completions = config.dialogs; }, - directory: function directory(context, tail) + directory: function directory(context, full) { - this.file(context, tail); - context.filters.push(function (item) this.getKey(item, "description") == "Directory"); + this.file(context, full); + context.filters.push(function ({ item: f }) f.isDirectory()); }, environment: function environment(context) @@ -1468,40 +1468,39 @@ function Completion() //{{{ // TODO: support file:// and \ or / path separators on both platforms // if "tail" is true, only return names without any directory components - file: function file(context, tail) + file: function file(context, full) { - let [dir] = context.filter.match(/^(?:.*[\/\\])?/); // dir == "" is expanded inside readDirectory to the current dir + let [dir] = context.filter.match(/^(?:.*[\/\\])?/); - context.title = ["Path", "Type"]; - if (tail) + if (!full) context.advance(dir.length); - context.keys = { text: 0, description: 1, icon: 2 }; + + context.title = [full ? "Path" : "Filename", "Type"]; + context.keys = { + text: !full ? "leafName" : function (f) dir + f.leafName, + description: function (f) f.isDirectory() ? "Directory" : "File", + icon: function (f) f.isDirectory() ? "resource://gre/res/html/folder.png" + : "moz-icon://" + f.leafName + }; + context.compare = function ({ item: a }, { item: b }) + b.isDirectory() - a.isDirectory() || String.localeCompare(a.path, b.path); + + if (options["wildignore"]) + { + let wigRegexp = RegExp("(^" + options.get("wildignore").values.join("|") + ")$"); + context.filters.push(function ({item: f}) f.isDirectory() || !wigRegexp.test(f.leafName)); + } + // context.background = true; context.key = dir; context.generate = function generate_file() { - context.cache.dir = dir; - try { - let files = io.readDirectory(dir); - - if (options["wildignore"]) - { - let wigRegexp = RegExp("(^" + options["wildignore"].replace(",", "|", "g") + ")$"); - files = files.filter(function (f) f.isDirectory() || !wigRegexp.test(f.leafName)) - } - - return files.map( - function (file) [tail ? file.leafName : dir + file.leafName, - file.isDirectory() ? "Directory" : "File", - file.isDirectory() ? "resource://gre/res/html/folder.png" - : "moz-icon://" + file.leafName] - ); + return io.readDirectory(dir); } catch (e) {} - return []; }; }, diff --git a/common/content/io.js b/common/content/io.js index 28b2d97f..227c5568 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -589,8 +589,7 @@ function IO() //{{{ while (entries.hasMoreElements()) { let entry = entries.getNext(); - entry.QueryInterface(Ci.nsIFile); - array.push(entry); + array.push(entry.QueryInterface(Ci.nsIFile)); } if (sort) return array.sort(function (a, b) b.isDirectory() - a.isDirectory() || String.localeCompare(a.path, b.path));