1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-09 00:04:11 +01:00

Remove unnecessary use of values() when iterating over arrays.

This commit is contained in:
Doug Kearns
2015-05-11 23:56:31 +10:00
parent a8e70d3f43
commit 48acf656ec
27 changed files with 81 additions and 80 deletions

View File

@@ -54,7 +54,7 @@ var updateAddons = Class("UpgradeListener", AddonListener, {
this.remaining = addons;
this.upgrade = [];
this.dactyl.echomsg(_("addon.check", addons.map(a => a.name).join(", ")));
for (let addon of values(addons))
for (let addon of addons)
addon.findUpdates(this, AddonManager.UPDATE_WHEN_USER_REQUESTED, null, null);
},

View File

@@ -377,7 +377,7 @@ deprecated.warn = function warn(func, name, alternative, frame) {
* object.
*
* @param {object} obj The object to inspect.
* @returns {Generator}
* @returns {Iter}
*/
function keys(obj) {
if (isinstance(obj, ["Map"]))
@@ -392,7 +392,7 @@ function keys(obj) {
* object.
*
* @param {object} obj The object to inspect.
* @returns {Generator}
* @returns {Iter}
*/
function values(obj) {
if (isinstance(obj, ["Map"]))
@@ -458,7 +458,7 @@ Object.defineProperty(RealSet.prototype, "union", {
this.Set = deprecated("RealSet", function Set(ary) {
let obj = {};
if (ary)
for (let val of values(ary))
for (let val of ary)
obj[val] = true;
return obj;
});
@@ -1528,7 +1528,7 @@ function iter(obj, iface) {
res = Ary.iterItems(obj);
else if (obj.constructor instanceof ctypes.StructType)
res = (function* () {
for (let prop of values(obj.constructor.fields)) {
for (let prop of obj.constructor.fields) {
let [name, type] = Iterator(prop).next();
yield [name, obj[name]];
}
@@ -1849,7 +1849,7 @@ var Ary = Class("Ary", Array, {
* given predicate.
*/
nth: function nth(ary, pred, n, self) {
for (let elem of values(ary))
for (let elem of ary)
if (pred.call(self, elem) && n-- === 0)
return elem;
return undefined;

View File

@@ -125,7 +125,7 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
get: function (url) {
let ids = services.bookmarks.getBookmarkIdsForURI(newURI(url), {});
for (let id of values(ids))
for (let id of ids)
if (id in this.bookmarks)
return this.bookmarks[id];
return null;

View File

@@ -525,13 +525,13 @@ var Buffer = Module("Buffer", {
Hints.isVisible);
for (let test of [a, b])
for (let regexp of values(regexps))
for (let regexp of regexps)
for (let i of util.range(res.length, 0, -1))
if (test(regexp, res[i]))
yield res[i];
}
for (let frame of values(this.allFrames(null, true)))
for (let frame of this.allFrames(null, true))
for (let elem of followFrame(frame))
if (count-- === 0) {
if (follow)
@@ -2045,7 +2045,7 @@ var Buffer = Module("Buffer", {
context.title = ["Stylesheet", "Location"];
// unify split style sheets
let styles = iter([s.title, []] for (s of values(buffer.alternateStyleSheets))).toObject();
let styles = iter([s.title, []] for (s of buffer.alternateStyleSheets)).toObject();
buffer.alternateStyleSheets.forEach(function (style) {
styles[style.title].push(style.href || _("style.inline"));
@@ -2506,7 +2506,7 @@ var Buffer = Module("Buffer", {
{
getLine: function getLine(doc, line) {
let uri = util.newURI(doc.documentURI);
for (let filter of values(this.value))
for (let filter of this.value)
if (filter(uri, doc)) {
if (/^func:/.test(filter.result))
var res = dactyl.userEval("(" + Option.dequote(filter.result.substr(5)) + ")")(doc, line);
@@ -2613,7 +2613,7 @@ Buffer.addPageInfoSection("e", "Search Engines", function* (verbose) {
let n = 1;
let nEngines = 0;
for (let { document: doc } of values(this.allFrames())) {
for (let { document: doc } of this.allFrames()) {
let engines = DOM("link[href][rel=search][type='application/opensearchdescription+xml']", doc);
nEngines += engines.length;

View File

@@ -576,7 +576,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
_("command.wontReplace", name));
}
for (let name of values(names)) {
for (let name of names) {
ex.__defineGetter__(name, function () this._run(name));
if (name in this._map && !this._map[name].isPlaceholder)
this.remove(name);
@@ -587,7 +587,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
memoize(this._map, name, () => commands.Command(specs, description, action, extra));
if (!extra.hidden)
memoize(this._list, this._list.length, closure);
for (let alias of values(names.slice(1)))
for (let alias of names.slice(1))
memoize(this._map, alias, closure);
return name;
@@ -647,7 +647,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
let cmd = this.get(name);
this._list = this._list.filter(c => c !== cmd);
for (let name of values(cmd.names))
for (let name of cmd.names)
delete this._map[name];
}
});

View File

@@ -35,7 +35,7 @@ var Group = Class("Group", {
modifiable: true,
cleanup: function cleanup(reason) {
for (let hive of values(this.hives))
for (let hive of this.hives)
util.trapErrors("cleanup", hive);
this.hives = [];
@@ -46,7 +46,7 @@ var Group = Class("Group", {
this.children.splice(0).forEach(this.contexts.bound.removeGroup);
},
destroy: function destroy(reason) {
for (let hive of values(this.hives))
for (let hive of this.hives)
util.trapErrors("destroy", hive);
if (reason != "shutdown")
@@ -154,7 +154,7 @@ var Contexts = Module("contexts", {
},
destroy: function () {
for (let hive of values(this.groupList.slice()))
for (let hive of this.groupList.slice())
util.trapErrors("destroy", hive, "shutdown");
for (let plugin of values(this.modules.plugins.contexts)) {
@@ -706,7 +706,7 @@ var Contexts = Module("contexts", {
arguments: [group.name],
ignoreDefaults: true
}
for (group of values(contexts.initializedGroups()))
for (group of contexts.initializedGroups())
if (!group.builtin && group.persist)
].concat([{ command: this.name, arguments: ["user"] }])
});

View File

@@ -1048,7 +1048,7 @@ var DOM = Class("DOM", {
this.code_nativeKey = {};
for (let list of values(this.keyTable))
for (let v of values(list)) {
for (let v of list) {
if (v.length == 1)
v = v.toLowerCase();
this.key_key[v.toLowerCase()] = v;
@@ -1477,7 +1477,7 @@ var DOM = Class("DOM", {
*/
compileMatcher: function compileMatcher(list) {
let xpath = [], css = [];
for (let elem of values(list))
for (let elem of list)
if (/^xpath:/.test(elem))
xpath.push(elem.substr(6));
else

View File

@@ -357,7 +357,7 @@ var DownloadList = Class("DownloadList",
let active = downloads.filter(d => d.active);
let self = Object.create(this);
for (let prop of values(["currentBytes", "totalBytes", "speed", "timeRemaining"]))
for (let prop of ["currentBytes", "totalBytes", "speed", "timeRemaining"])
this[prop] = active.reduce((acc, dl) => dl[prop] + acc, 0);
this.hasProgress = active.every(d => d.hasProgress);
@@ -368,7 +368,7 @@ var DownloadList = Class("DownloadList",
if (active.length)
this.nodes.total.textContent = _("download.nActive", active.length);
else for (let key of values(["total", "percent", "speed", "time"]))
else for (let key of ["total", "percent", "speed", "time"])
this.nodes[key].textContent = "";
if (this.shouldSort("complete", "size", "speed", "time"))

View File

@@ -52,7 +52,7 @@ var HelpBuilder = Class("HelpBuilder", {
// Find the tags in the document.
addTags: function addTags(file, doc) {
for (let elem of DOM.XPath("//@tag|//dactyl:tags/text()|//dactyl:tag/text()", doc))
for (let tag of values((elem.value || elem.textContent).split(/\s+/)))
for (let tag of (elem.value || elem.textContent).split(/\s+/))
this.tags[tag] = file;
},
@@ -61,7 +61,7 @@ var HelpBuilder = Class("HelpBuilder", {
// Find help and overlay files with the given name.
findHelpFile: function findHelpFile(file) {
let result = [];
for (let base of values(this.bases)) {
for (let base of this.bases) {
let url = [base, file, ".xml"].join("");
let res = util.httpGet(url, { quiet: true });
if (res) {
@@ -211,7 +211,7 @@ var Help = Module("Help", {
flush: function flush(entries, time) {
cache.flushEntry("help.json", time);
for (let entry of values(Array.concat(entries || [])))
for (let entry of Array.concat(entries || []))
cache.flushEntry(entry, time);
},

View File

@@ -97,7 +97,7 @@ var IO = Module("io", {
dactyl.echomsg(_("io.searchingFor", JSON.stringify(paths.join(" ")), modules.options.get("runtimepath").stringValue), 2);
outer:
for (let dir of values(dirs)) {
for (let dir of dirs) {
for (let path of paths) {
let file = dir.child(path);
@@ -627,7 +627,7 @@ var IO = Module("io", {
}
else {
let dirs = modules.options.get("cdpath").files;
for (let dir of values(dirs)) {
for (let dir of dirs) {
dir = dir.child(arg);
if (dir.exists() && dir.isDirectory() && dir.isReadable()) {

View File

@@ -288,7 +288,7 @@ overlay.overlayWindow(Object.keys(config.overlays),
if (seen.add(module.className))
throw Error("Module dependency loop.");
for (let dep of values(module.requires))
for (let dep of module.requires)
this.loadModule(Module.constructors[dep], module.className);
defineModule.loadLog.push(

View File

@@ -489,7 +489,7 @@ var Option = Class("Option", {
get charlist() this.stringlist,
regexplist: function regexplist(k, default_=null) {
for (let re of values(this.value))
for (let re of this.value)
if ((re.test || re).call(re, k))
return re.result;
return default_;
@@ -814,7 +814,7 @@ var Option = Class("Option", {
update(BooleanOption.prototype, {
names: Class.Memoize(function ()
Ary.flatten([[name, "no" + name] for (name of values(this.realNames))]))
Ary.flatten([[name, "no" + name] for (name of this.realNames)]))
});
var OptionHive = Class("OptionHive", Contexts.Hive, {
@@ -966,7 +966,7 @@ var Options = Module("options", {
memoize(this._optionMap, name,
function () Option.types[type](modules, names, description, defaultValue, extraInfo));
for (let alias of values(names.slice(1)))
for (let alias of names.slice(1))
memoize(this._optionMap, alias, closure);
if (extraInfo.setter && (!extraInfo.scope || extraInfo.scope & Option.SCOPE_GLOBAL))
@@ -1099,7 +1099,7 @@ var Options = Module("options", {
remove: function remove(name) {
let opt = this.get(name);
this._options = this._options.filter(o => o != opt);
for (let name of values(opt.names))
for (let name of opt.names)
delete this._optionMap[name];
},
@@ -1167,7 +1167,7 @@ var Options = Module("options", {
modules.commandline.input(_("pref.prompt.resetAll", config.host) + " ",
function (resp) {
if (resp == "yes")
for (let pref of values(prefs.getNames()))
for (let pref of prefs.getNames())
prefs.reset(pref);
},
{ promptHighlight: "WarningMsg" });
@@ -1315,7 +1315,7 @@ var Options = Module("options", {
// Fill in the current values if we're removing
if (opt.operator == "-" && isArray(opt.values)) {
let have = new RealSet(i.text for (i of values(context.allItems.items)));
let have = new RealSet(i.text for (i of context.allItems.items));
context = context.fork("current-values", 0);
context.anchored = optcontext.anchored;
context.maxItems = optcontext.maxItems;
@@ -1582,7 +1582,7 @@ var Options = Module("options", {
description: "Options containing hostname data",
action: function sanitize_action(timespan, host) {
if (host)
for (let opt of values(modules.options._options))
for (let opt of modules.options._options)
if (timespan.contains(opt.lastSet * 1000) && opt.domains)
try {
opt.value = opt.filterDomain(host, opt.value);

View File

@@ -57,7 +57,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
if (this == prefs) {
if (~["uninstall", "disable"].indexOf(reason)) {
for (let name of values(this.branches.saved.getNames()))
for (let name of this.branches.saved.getNames())
this.safeReset(name, null, true);
this.branches.original.resetBranch();

View File

@@ -20,7 +20,7 @@ var Binding = Class("Binding", {
Object.defineProperties(node, this.constructor.properties);
for (let [event, handler] of values(this.constructor.events))
for (let [event, handler] of this.constructor.events)
node.addEventListener(event, util.wrapCallback(handler, true), false);
},
@@ -74,7 +74,7 @@ var Binding = Class("Binding", {
for (let prop of properties(obj)) {
let desc = Object.getOwnPropertyDescriptor(obj, prop);
if (desc.enumerable) {
for (let k of values(["get", "set", "value"]))
for (let k of ["get", "set", "value"])
if (typeof desc[k] === "function")
desc[k] = this.bind(desc[k]);
res[prop] = desc;

View File

@@ -1173,7 +1173,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
"dactyl-cleanup-modules": function cleanupModules(subject, reason) {
defineModule.loadLog.push("dactyl: util: observe: dactyl-cleanup-modules " + reason);
for (let module of values(defineModule.modules))
for (let module of defineModule.modules)
if (module.cleanup) {
util.dump("cleanup: " + module.constructor.className);
util.trapErrors(module.cleanup, module, reason);