1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-14 17:45:45 +01:00

Use real Sets rather than objects in most places.

This commit is contained in:
Kris Maglione
2014-02-15 18:10:45 -08:00
parent e3fb435f99
commit fd20535999
29 changed files with 353 additions and 262 deletions

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2010 by anekos <anekos@snca.net>
// Copyright (c) 2010-2013 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2010-2014 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -132,7 +132,8 @@ var AbbrevHive = Class("AbbrevHive", Contexts.Hive, {
*/
get: function (mode, lhs) {
let abbrevs = this._store[mode];
return abbrevs && Set.has(abbrevs, lhs) ? abbrevs[lhs] : null;
return abbrevs && hasOwnProperty(abbrevs, lhs) ? abbrevs[lhs]
: null;
},
/**

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -73,7 +73,7 @@ var Bookmarks = Module("bookmarks", {
if (id != null)
var bmark = bookmarkcache.bookmarks[id];
else if (!force) {
if (keyword && Set.has(bookmarkcache.keywords, keyword))
if (keyword && hasOwnProperty(bookmarkcache.keywords, keyword))
bmark = bookmarkcache.keywords[keyword];
else if (bookmarkcache.isBookmarked(uri))
for (bmark in bookmarkcache)
@@ -223,7 +223,7 @@ var Bookmarks = Module("bookmarks", {
if (!alias)
alias = "search"; // for search engines which we can't find a suitable alias
if (Set.has(aliases, alias))
if (hasOwnProperty(aliases, alias))
alias += ++aliases[alias];
else
aliases[alias] = 0;
@@ -251,10 +251,10 @@ var Bookmarks = Module("bookmarks", {
getSuggestions: function getSuggestions(engineName, query, callback) {
const responseType = "application/x-suggestions+json";
if (Set.has(this.suggestionProviders, engineName))
if (hasOwnProperty(this.suggestionProviders, engineName))
return this.suggestionProviders[engineName](query, callback);
let engine = Set.has(this.searchEngines, engineName) && this.searchEngines[engineName];
let engine = hasOwnProperty(this.searchEngines, engineName) && this.searchEngines[engineName];
if (engine && engine.supportsResponseType(responseType))
var queryURI = engine.getSubmission(query, responseType).uri.spec;
if (!queryURI)
@@ -320,7 +320,7 @@ var Bookmarks = Module("bookmarks", {
param = query.substr(offset + 1);
}
var engine = Set.has(bookmarks.searchEngines, keyword) && bookmarks.searchEngines[keyword];
var engine = hasOwnProperty(bookmarks.searchEngines, keyword) && bookmarks.searchEngines[keyword];
if (engine) {
if (engine.searchForm && !param)
return engine.searchForm;
@@ -700,7 +700,7 @@ var Bookmarks = Module("bookmarks", {
let engine = bookmarks.searchEngines[name];
if (engine)
var desc = engine.description;
else if (!Set.has(bookmarks.suggestionProviders, name))
else if (!hasOwnProperty(bookmarks.suggestionProviders, name))
return;
let [, word] = /^\s*(\S+)/.exec(context.filter) || [];

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -278,7 +278,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let results = array((params.iterateIndex || params.iterate).call(params, commands.get(name).newArgs()))
.array.sort((a, b) => String.localeCompare(a.name, b.name));
let haveTag = Set.has(help.tags);
let haveTag = hasOwnProperty(help.tags);
for (let obj in values(results)) {
let res = dactyl.generateHelp(obj, null, null, true);
if (!haveTag(obj.helpTag))
@@ -620,7 +620,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* @param {string} feature The feature name.
* @returns {boolean}
*/
has: function has(feature) Set.has(config.features, feature),
has: function has(feature) config.has(feature),
/**
* @private

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
//
// This work is licensed for reuse under an MIT license. Details are
@@ -68,7 +68,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
name = 0;
if (name == "_")
var res = null;
else if (Set.has(this.selectionRegisters, name))
else if (hasOwnProperty(this.selectionRegisters, name))
res = { text: dactyl.clipboardRead(this.selectionRegisters[name]) || "" };
else if (!/^[0-9]$/.test(name))
res = this.registers.get(name);
@@ -105,7 +105,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
name = 0;
if (name == "_")
;
else if (Set.has(this.selectionRegisters, name))
else if (hasOwnProperty(this.selectionRegisters, name))
dactyl.clipboardWrite(value.text, verbose, this.selectionRegisters[name]);
else if (!/^[0-9]$/.test(name))
this.registers.set(name, value);
@@ -1363,11 +1363,12 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
args.push(obj["file"]);
return args;
},
has: function (key) Set.has(util.compileMacro(this.value).seen, key),
has: function (key) util.compileMacro(this.value).seen.has(key),
validator: function (value) {
this.format({}, value);
return Object.keys(util.compileMacro(value).seen)
.every(k => ["column", "file", "line"].indexOf(k) >= 0);
let allowed = RealSet(["column", "file", "line"]);
return [k for (k of util.compileMacro(value).seen)]
.every(k => allowed.has(k));
}
});

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -28,7 +28,7 @@ var EventHive = Class("EventHive", Contexts.Hive, {
else
[self, events] = [event, event[callback || "events"]];
if (Set.has(events, "input") && !Set.has(events, "dactyl-input"))
if (hasOwnProperty(events, "input") && !hasOwnProperty(events, "dactyl-input"))
events["dactyl-input"] = events.input;
return [self, events];
@@ -79,7 +79,7 @@ var EventHive = Class("EventHive", Contexts.Hive, {
let elem = args[0].get();
if (target == null || elem == target
&& self == args[1].get()
&& Set.has(events, args[2])
&& hasOwnProperty(events, args[2])
&& args[3].wrapped == events[args[2]]
&& args[4] == capture) {
@@ -1124,12 +1124,12 @@ var Events = Module("events", {
"sitemap", "", {
flush: function flush() {
memoize(this, "filters", function () this.value.filter(function (f) f(buffer.documentURI)));
memoize(this, "pass", function () Set(array.flatten(this.filters.map(function (f) f.keys))));
memoize(this, "pass", function () RealSet(array.flatten(this.filters.map(function (f) f.keys))));
memoize(this, "commandHive", function hive() Hive(this.filters, "command"));
memoize(this, "inputHive", function hive() Hive(this.filters, "input"));
},
has: function (key) Set.has(this.pass, key) || Set.has(this.commandHive.stack.mappings, key),
has: function (key) this.pass.has(key) || hasOwnProperty(this.commandHive.stack.mappings, key),
get pass() (this.flush(), this.pass),

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -39,7 +39,7 @@ var Map = Class("Map", {
Object.freeze(this.modes);
if (info) {
if (Set.has(Map.types, info.type))
if (hasOwnProperty(Map.types, info.type))
this.update(Map.types[info.type]);
this.update(info);
}
@@ -380,11 +380,13 @@ var Mappings = Module("mappings", {
},
iterate: function (mode) {
let seen = {};
let seen = RealSet();
for (let hive in this.hives.iterValues())
for (let map in array(hive.getStack(mode)).iterValues())
if (!Set.add(seen, map.name))
if (!seen.has(map.name)) {
seen.add(map.name);
yield map;
}
},
// NOTE: just normal mode for now
@@ -638,11 +640,13 @@ var Mappings = Module("mappings", {
}
};
function userMappings(hive) {
let seen = {};
let seen = RealSet();
for (let stack in values(hive.stacks))
for (let map in array.iterValues(stack))
if (!Set.add(seen, map.id))
if (!seen.has(map.id)) {
seen.add(map.id);
yield map;
}
}
modeDescription = modeDescription ? " in " + modeDescription + " mode" : "";
@@ -748,13 +752,14 @@ var Mappings = Module("mappings", {
if (!mainOnly)
modes = modes[0].allBases;
let seen = {};
let seen = RealSet();
// Bloody hell. --Kris
for (let [i, mode] in Iterator(modes))
for (let hive in mappings.hives.iterValues())
for (let map in array.iterValues(hive.getStack(mode)))
for (let name in values(map.names))
if (!Set.add(seen, name)) {
if (!seen.has(name)) {
seen.add(name);
yield {
name: name,
columns: [
@@ -800,7 +805,7 @@ var Mappings = Module("mappings", {
name: [mode.char + "listk[eys]", mode.char + "lk"],
iterateIndex: function (args)
let (self = this, prefix = /^[bCmn]$/.test(mode.char) ? "" : mode.char + "_",
haveTag = Set.has(help.tags))
haveTag = k => hasOwnProperty(help.tags, k))
({ helpTag: prefix + map.name, __proto__: map }
for (map in self.iterate(args, true))
if (map.hive === mappings.builtin || haveTag(prefix + map.name))),

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -446,9 +446,12 @@ var Modes = Module("modes", {
this.allBases.indexOf(obj) >= 0 || callable(obj) && this instanceof obj,
allBases: Class.Memoize(function () {
let seen = {}, res = [], queue = [this].concat(this.bases);
let seen = RealSet(),
res = [],
queue = [this].concat(this.bases);
for (let mode in array.iterValues(queue))
if (!Set.add(seen, mode)) {
if (!seen.has(mode)) {
seen.add(mode);
res.push(mode);
queue.push.apply(queue, mode.bases);
}
@@ -491,7 +494,7 @@ var Modes = Module("modes", {
StackElement.defaultValue("params", function () this.main.params);
update(StackElement.prototype, {
get toStringParams() !loaded.modes ? this.main.name : [
get toStringParams() !loaded.modes ? [this.main.name] : [
this.main.name,
["(", modes.all.filter(m => this.extended & m)
.map(m => m.name)
@@ -604,7 +607,7 @@ var Modes = Module("modes", {
return (array.nth(this.value, v => val.some(m => m.name === v.mode), 0)
|| { result: default_ }).result;
return Set.has(this.valueMap, val) ? this.valueMap[val] : default_;
return hasOwnProperty(this.valueMap, val) ? this.valueMap[val] : default_;
},
setter: function (vals) {
@@ -622,7 +625,7 @@ var Modes = Module("modes", {
},
validator: function validator(vals) vals.map(v => v.replace(/^!/, ""))
.every(Set.has(this.values)),
.every(k => hasOwnProperty(this.values, k)),
get values() array.toObject([[m.name.toLowerCase(), m.description] for (m in values(modes._modes)) if (!m.hidden)])
};

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -1036,7 +1036,7 @@ var Tabs = Module("tabs", {
tabs.getGroups();
tabs[visible ? "visibleTabs" : "allTabs"].forEach(function (tab, i) {
let group = (tab.tabItem || tab._tabViewTabItem || defItem).parent || defItem.parent;
if (!Set.has(tabGroups, group.id))
if (!hasOwnProperty(tabGroups, group.id))
tabGroups[group.id] = [group.getTitle(), []];
group = tabGroups[group.id];
@@ -1261,11 +1261,11 @@ var Tabs = Module("tabs", {
values: activateGroups,
has: Option.has.toggleAll,
setter: function (newValues) {
let valueSet = Set(newValues);
let valueSet = RealSet(newValues);
for (let group in values(activateGroups))
if (group[2])
prefs.safeSet("browser.tabs." + group[2],
!(valueSet["all"] ^ valueSet[group[0]]),
!(valueSet.has("all") ^ valueSet.has(group[0])),
_("option.safeSet", "activate"));
return newValues;
}