cache variable lookup for a 20% speedup

This commit is contained in:
cloudhead
2010-03-07 23:02:16 -05:00
parent be893c5993
commit a68a2fc6bf

View File

@@ -7,9 +7,12 @@ tree.Ruleset = function Ruleset(selectors, rules) {
tree.Ruleset.prototype = {
eval: function () { return this },
variables: function () {
return this.rules.filter(function (r) {
if (r instanceof tree.Rule && r.variable === true) { return r }
});
if (this._variables) { return this._variables }
else {
return this._variables = this.rules.filter(function (r) {
if (r instanceof tree.Rule && r.variable === true) { return r }
});
}
},
find: function (selector, self) {
self = self || this;