1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 09:48:00 +01:00

speed up Struct slightly and don't use it for History for now. (Still doesn't fix all perf problems, as it is still used in many other places like styles).

This commit is contained in:
Martin Stubenschrott
2008-11-13 23:05:04 +00:00
parent 074df859c5
commit 1f056ad06c
2 changed files with 13 additions and 8 deletions

View File

@@ -549,9 +549,9 @@ function History() //{{{
const historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService);
const History = new Struct("url", "title", "icon");
History.defaultValue("title", function () "[No Title]");
History.defaultValue("icon", function () bookmarks.getFavicon(this.url));
// const History = new Struct("url", "title", "icon");
// History.defaultValue("title", function () "[No Title]");
// History.defaultValue("icon", function () bookmarks.getFavicon(this.url));
var placesHistory;
var cachedHistory = []; // add pages here after loading the initial Places history
@@ -575,7 +575,7 @@ function History() //{{{
var node = rootNode.getChild(i);
// liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type);
if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark
placesHistory.push(History(node.uri, node.title))
placesHistory.push({ url: node.uri, title: node.title, get icon() function() bookmarks.getFavicon(this.url) });
}
// close a container after using it!
@@ -766,7 +766,7 @@ function History() //{{{
if (placesHistory.some(function (h) h[0] == url))
placesHistory = placesHistory.filter(filter);
cachedHistory.unshift(History(url, title));
cachedHistory.unshift({ url: url, title: title, get icon() function() bookmarks.getFavicon(this.url) });
return true;
},

View File

@@ -485,6 +485,9 @@ const util = { //{{{
}
}; //}}}
// Struct is really slow, AT LEAST 5 times slower than using structs or simple Objects
// main reason is the function ConStructor(), which i couldn't get faster.
// Maybe it's a TraceMonkey problem, for now don't use it for anything which must be fast (like bookmarks or history)
function Struct()
{
let self = this instanceof Struct ? this : new Struct();
@@ -503,11 +506,13 @@ function Struct()
function ConStructor()
{
let self = this instanceof arguments.callee ? this : new arguments.callee();
for (let [k, v] in Iterator(Array.slice(arguments)))
//for (let [k, v] in Iterator(Array.slice(arguments))) // That is makes using struct twice as slow as the following code:
for (let i = 0; i < arguments.length; i++)
{
if (v != undefined)
self[k] = v;
if (arguments[i] != undefined)
self[i] = arguments[i];
}
return self;
}
ConStructor.prototype = self;