Skip to content

Commit

Permalink
[compiler] small compile performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Nov 8, 2011
1 parent 31eac69 commit c9fdddd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions lib/xjst/compiler.js
Expand Up @@ -96,15 +96,15 @@ exports.generate = function generate(templatesAndOther, options) {
var predicate = s[0],
predicateConst = s[2];

return predicMemo.hasOwnProperty(predicate) &&
return predicMemo[predicate] !== undefined &&
predicMemo[predicate] != utils.stringify(predicateConst);
});
if (known) return traverse(i + 1, 0, predicMemo);

var predicate = subMatch[0],
predicateConst = subMatch[2];

if(predicMemo.hasOwnProperty(predicate)) {
if(predicMemo[predicate] !== undefined) {
if(predicMemo[predicate] === utils.stringify(predicateConst)) {
return traverse(i, j + 1, predicMemo);
} else {
Expand All @@ -121,7 +121,7 @@ exports.generate = function generate(templatesAndOther, options) {
});
result.default = traverse(i, j, utils.cloneChanged(predicMemo,
predicate,
undefined));
null));
return addNode(merge(result), predicMemo);
}
};
Expand All @@ -140,7 +140,7 @@ exports.generate = function generate(templatesAndOther, options) {
return _parents.concat(o.longId || o.id);
};

if(merges.hasOwnProperty(o.id)) {
if(merges[o.id] !== undefined) {
tails[o.id] = o;
if (o.tag) {
return [
Expand Down Expand Up @@ -239,7 +239,7 @@ exports.generate = function generate(templatesAndOther, options) {

function detectJoins(o, joins) {
if(o.id) {
if(joins.hasOwnProperty(o.id)) {
if(joins[o.id] !== undefined) {
joins[o.id]++;
} else {
joins[o.id] = 1;
Expand Down Expand Up @@ -360,6 +360,7 @@ exports.generate = function generate(templatesAndOther, options) {
};

function optimizeRecursion(tree) {
console.log('>> optimizeRecursion <<');
// Update predicates with data in local
var applies = reduceTree(tree, function(acc, node) {
if (!node.stmt) return acc;
Expand Down
8 changes: 4 additions & 4 deletions lib/xjst/utils.js
Expand Up @@ -40,7 +40,7 @@ Identifier.prototype.identify = function identify(o) {
var cache = this.cache,
key = JSON.stringify(o);

if(cache.hasOwnProperty(key)) {
if(cache[key] !== undefined) {
return cache[key];
} else {
return cache[key] = ++this.counter;
Expand All @@ -63,7 +63,7 @@ utils.join = function(result, a, values, unique) {
var matched = values[key],
val;

if (a[key] === undefined) {
if (a[key] === null) {
result[matched] = [unique.generate()];
return;
}
Expand Down Expand Up @@ -156,7 +156,7 @@ utils.clone = function clone(object, stringify) {
var result = {};

Object.keys(object).forEach(function(i) {
if (stringify && object[i] === undefined) return;
if (stringify && object[i] === null) return;
result[i] = stringify ? utils.stringify(object[i]) : object[i];
});

Expand Down Expand Up @@ -206,7 +206,7 @@ Merger.prototype.merge = function merge(obj) {

obj.size = size;

if(this.cache.hasOwnProperty(hash)) {
if(this.cache[hash] !== undefined) {
obj.id = this.cache[hash].id;
} else {
this.cache[obj.hash = hash] = obj;
Expand Down

0 comments on commit c9fdddd

Please sign in to comment.