Skip to content

Commit

Permalink
noop: make first execution faster by wrapping some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Jan 24, 2017
1 parent 04d8ad1 commit 7dbaef9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
8 changes: 4 additions & 4 deletions background/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var Commands = {
registry[pair[0]] = Utils.makeCommand(pair[1]);
}
},
parseKeyMappings: function(line) {
parseKeyMappings: (function(line) {
var key, lines, splitLine, mk = 0, _i = 0, _len, mkReg, registry, details, available;
registry = CommandsData.keyToCommandRegistry = Object.create(null);
mkReg = Object.create(null);
Expand Down Expand Up @@ -96,8 +96,8 @@ var Commands = {
}
}
CommandsData.mapKeyRegistry = mk > 0 ? mkReg : null;
},
populateCommandKeys: function() {
}),
populateCommandKeys: (function() {
var key, ref, ref2, arr, keyRe = Utils.keyRe, ch, j, last, tmp, func;
ref = Object.create(null);
for (ch = 10; 0 <= --ch; ) { ref[ch] = 1; }
Expand Down Expand Up @@ -144,7 +144,7 @@ var Commands = {
}
Settings.Init && Settings.Init();
return ref;
},
}),

defaultKeyMappings: [
["?", "showHelp"],
Expand Down
19 changes: 9 additions & 10 deletions background/help_dialog.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
var HelpDialog = {
render: function(request) {
render: (function(request) {
var command, commandsToKey, key, ref = CommandsData.keyToCommandRegistry, result;
Object.setPrototypeOf(request, null);
commandsToKey = Object.create(null);
Expand All @@ -20,8 +20,8 @@ var HelpDialog = {
return s != null ? s
: HelpDialog.groupHtml(group, commandsToKey, CommandsData.availableCommands, showUnbound, showNames);
});
},
groupHtml: function(group, commandsToKey, availableCommands, showUnbound, showNames) {
}),
groupHtml: (function(group, commandsToKey, availableCommands, showUnbound, showNames) {
var bindings, command, html, isAdvanced, _i, _len, _ref, keys, description, push;
html = [];
_ref = this.commandGroups[group];
Expand All @@ -46,8 +46,8 @@ var HelpDialog = {
}
}
return html.join("");
},
commandHtml: function(html, isAdvanced, bindings, description, command) {
}),
commandHtml: (function(html, isAdvanced, bindings, description, command) {
html.push('<tr class="HelpTr', isAdvanced ? " HelpAdv" : "", '">\n\t');
if (description) {
html.push('<td class="HelpTd HelpKeys">'
Expand All @@ -62,7 +62,7 @@ var HelpDialog = {
, bindings);
}
html.push("</td>\n</tr>\n");
},
}),
commandGroups: {
pageNavigation: ["scrollDown", "scrollUp", "scrollLeft", "scrollRight", "scrollToTop"
, "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown", "scrollPageUp"
Expand Down Expand Up @@ -98,9 +98,8 @@ var HelpDialog = {
misc: ["showHelp", "autoCopy", "autoOpen", "searchAs", "searchInAnother", "toggleLinkHintCharacters"
, "toggleSwitchTemp", "passNextKey", "debugBackground", "blank"]
},
advancedCommands: {
__proto__: null
, toggleViewSource: 1, clearFindHistory: 1
advancedCommands: Object.setPrototypeOf({
toggleViewSource: 1, clearFindHistory: 1
, scrollToLeft: 1, scrollToRight: 1, moveTabToNextWindow: 1
, moveTabToNewWindow: 1, moveTabToIncognito: 1, reloadGivenTab: 1, focusOrLaunch: 1
, goUp: 1, goToRoot: 1, focusInput: 1, "LinkHints.activateModeWithQueue": 1, enableCSTemp: 1
Expand All @@ -114,5 +113,5 @@ var HelpDialog = {
, "LinkHints.activateModeToHover": 1, "LinkHints.unhoverLast": 1
, toggleLinkHintCharacters: 1, toggleSwitchTemp: 1, "LinkHints.activateModeToLeave": 1
, "Vomnibar.activateEditUrl": 1, "Vomnibar.activateEditUrlInNewTab": 1
}
}, null)
};
12 changes: 6 additions & 6 deletions background/others.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if (Settings.get("vimSync") === true) setTimeout(function() { if (!chrome.storag
});
}, 400);

setTimeout(function() { if (!chrome.browserAction) { return; }
setTimeout((function() { if (!chrome.browserAction) { return; }
var func = Settings.updateHooks.showActionIcon, imageData, tabIds;
function loadImageAndSetIcon(type, path) {
var img, i, cache = Object.create(null), count = 0,
Expand Down Expand Up @@ -153,9 +153,9 @@ setTimeout(function() { if (!chrome.browserAction) { return; }
}
};
Settings.postUpdate("showActionIcon");
}, 150);
}), 150);

setTimeout(function() { if (!chrome.omnibox) { return; }
setTimeout((function() { if (!chrome.omnibox) { return; }
var last, firstResult, lastSuggest,
tempRequest, timeout = 0, sessionIds, suggestions = null, outTimeout = 0, outTime,
defaultSug = { description: "<dim>Open: </dim><url>%s</url>" },
Expand Down Expand Up @@ -291,7 +291,7 @@ setTimeout(function() { if (!chrome.omnibox) { return; }
};
chrome.omnibox.onInputChanged.addListener(onInput);
chrome.omnibox.onInputEntered.addListener(onEnter);
}, 600);
}), 600);

var a, cb;
// According to tests: onInstalled will be executed after 0 ~ 16 ms if needed
Expand Down Expand Up @@ -354,11 +354,11 @@ setTimeout(function() {
}, 500);
});

setTimeout(function() {
setTimeout((function() {
if (a) {
a.removeListener(cb);
chrome.runtime.onInstalled = a = null;
}
cb = function(b) { a = b; console.log(b); };
Utils.resetRe();
}, 1200);
}), 1200);
20 changes: 10 additions & 10 deletions background/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var Utils = {
_jsNotEscapeRe: /["\[\]{}\u00ff-\uffff]|%(?![\dA-F]{2}|[\da-f]{2})/,
filePathRe: /^['"]?((?:[A-Za-z]:[\\/]|\/(?:Users|home|root)\/)[^'"]*)['"]?$/,
lastUrlType: 0,
convertToUrl: function(string, keyword, vimiumUrlWork) {
convertToUrl: (function(string, keyword, vimiumUrlWork) {
string = string.trim();
if (string.charCodeAt(10) === 58 && string.substring(0, 11).toLowerCase() === "javascript:") {
if (Settings.CONST.ChromeVersion < 46 && string.indexOf('%', 11) > 0
Expand Down Expand Up @@ -175,7 +175,7 @@ var Utils = {
: type === 1 ? ("http://" + oldString)
: type === 2 ? ("http:" + oldString)
: oldString;
},
}),
checkSpecialSchemes: function(string, i, spacePos) {
var isSlash = string[i + 1] === "/";
switch (string.substring(0, i)) {
Expand Down Expand Up @@ -406,7 +406,7 @@ var Utils = {
} catch (e) {}
return url;
},
parseSearchEngines: function(str, map) {
parseSearchEngines: (function(str, map) {
var ids, pair, key, val, obj, _i, _len, ind, rSlash = /[^\\]\//, rules = [],
rEscapeSpace = /\\\s/g, rSpace = /\s/, rEscapeS = /\\s/g, rColon = /\\:/g,
rPercent = /\\%/g, rRe = /\sre=/i, a = str.replace(/\\\n/g, '').split('\n'),
Expand Down Expand Up @@ -489,12 +489,12 @@ var Utils = {
obj.name = str ? this.DecodeURLPart(str) : ids[ids.length - 1].trimLeft();
}
return rules;
},
}),
escapeAllRe: /[$()*+.?\[\\\]\^{|}]/g,
_spaceOrPlusRe: /\\\+|%20| /g,
_queryRe: /[#?]/,
alphaRe: /[a-z]/i,
reparseSearchUrl: function (url, ind) {
reparseSearchUrl: (function (url, ind) {
var prefix, str, str2, ind2;
if (!this.protocolRe.test(url)) { return; }
prefix = url.substring(0, ind - 1);
Expand Down Expand Up @@ -524,7 +524,7 @@ var Utils = {
).replace(this._spaceOrPlusRe, "(?:\\+|%20| )");
prefix = this.prepareReparsingPrefix(prefix);
return [prefix, new RegExp(str + str2 + url, this.alphaRe.test(str2) ? "i" : "")];
},
}),
prepareReparsingPrefix: function(prefix) {
if (prefix.startsWith("http://") || prefix.startsWith("https://")) {
prefix = prefix.substring(prefix[4] === 's' ? 8 : 7);
Expand Down Expand Up @@ -572,11 +572,11 @@ var Utils = {
};

if (!String.prototype.startsWith) {
String.prototype.startsWith = function(s) {
String.prototype.startsWith = (function(s) {
return this.length >= s.length && this.lastIndexOf(s, 0) === 0;
};
String.prototype.endsWith || (String.prototype.endsWith = function(s) {
});
String.prototype.endsWith || (String.prototype.endsWith = (function(s) {
var i = this.length - s.length;
return i >= 0 && this.indexOf(s, i) === i;
});
}));
}
8 changes: 4 additions & 4 deletions content/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ var VSettings, VHUD, VPort, VEventMode;
ClearPort: function() {
vPort.port = null;
},
connect: function(isFirst) {
connect: (function(isFirst) {
var port, data = { name: "vimium++." + ((window.top === window) * 4 + document.hasFocus() * 2 + isFirst) };
port = this.port = isInjected ? chrome.runtime.connect(VimiumInjector.id, data) : chrome.runtime.connect(data);
port.onDisconnect.addListener(this.ClearPort);
port.onMessage.addListener(this.Listener);
}
})
};
location.href !== "about:blank" || isInjected ? vPort.connect(1) :
(window.onload = function() { window.onload = null; setTimeout(function() {
Expand Down Expand Up @@ -204,13 +204,13 @@ var VSettings, VHUD, VPort, VEventMode;
HUD.enabled = true;
ELs.OnWndFocus = vPort.safePost.bind(vPort, { handler: "frameFocused" });
},
hook: function(f, c) {
hook: (function(f, c) {
f("keydown", this.onKeydown, true);
f("keyup", this.onKeyup, true);
c || f("focus", this.onFocus, true);
f("blur", this.onBlur, true);
f.call(document, "DOMActivate", ELs.onActivate, true);
}
})
};
ELs.hook(addEventListener);

Expand Down
4 changes: 2 additions & 2 deletions weidu/js/jqm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7dbaef9

Please sign in to comment.