diff options
author | alon@honor <none@none> | 2010-08-31 20:21:06 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-08-31 20:21:06 -0700 |
commit | 9426f471eca9b4f3d04906f613289d52c2dd6c9c (patch) | |
tree | 2a5638f93c2ff43772ed68e4f4d8f13f23ea44e4 | |
parent | da7a906536a26dca22190c870aaa96588dc92dec (diff) |
optimize makeCombiner
-rw-r--r-- | src/parser.js | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/parser.js b/src/parser.js index 7ee4361b..8158edf1 100644 --- a/src/parser.js +++ b/src/parser.js @@ -153,22 +153,25 @@ function makeSplitter(parentSlot, parentSlotValue, parentUnrequiredSlot, childSl function makeCombiner(parentSlot, parentSlotValue, parentUnrequiredSlot, childRequiredSlot, finalizeFunc) { return { select: function(items) { + var ret = []; var parents = items.filter(function(item) { return item[parentSlot] == parentSlotValue && !item[parentUnrequiredSlot] }); for (var i = 0; i < parents.length; i++) { var parent = parents[i]; var child = items.filter(function(item) { return item[childRequiredSlot] && item.parentUid === parent.__uid__ })[0]; - if (child) return [parent, child]; + if (child) { + ret = ret.concat([parent, child]); + } } - return []; + return ret; }, process: function(items) { - var parent = items[0]; - var child = items[1]; - parent[child.parentSlot] = child; - delete child.parentUid; - delete child.parentSlot; - finalizeFunc(parent); - return [parent]; + return Zyme.prototype.processPairs(items, function(parent, child) { + parent[child.parentSlot] = child; + delete child.parentUid; + delete child.parentSlot; + finalizeFunc(parent); + return [parent]; + }); }, }; } |