diff options
author | alon@honor <none@none> | 2010-09-05 16:30:28 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-05 16:30:28 -0700 |
commit | 3e6c745b828932f237e472c484bb2ac2abfb8e3e (patch) | |
tree | b53e663c5d4c644ce3cfc02a73e49efabaa9db3b /src/parser.js | |
parent | 33059350a3a86885dd4c73f3219162ec54d4c0d5 (diff) |
optimize makesplitter
Diffstat (limited to 'src/parser.js')
-rw-r--r-- | src/parser.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/parser.js b/src/parser.js index beb66ac9..491e31f5 100644 --- a/src/parser.js +++ b/src/parser.js @@ -141,15 +141,20 @@ function splitTokenList(tokens) { function makeSplitter(parentSlot, parentSlotValue, parentUnrequiredSlot, childSlot, copySlots) { return { selectItem: function(item) { return item[parentSlot] == parentSlotValue && !item[parentUnrequiredSlot] && item[childSlot] !== null }, - processItem: function(parent) { - var child = parent[childSlot]; - parent[childSlot] = null; - child.parentUid = parent.__uid__; - child.parentSlot = childSlot; - child.lineNum = parent.lineNum; // Debugging + process: function(parents) { if (!copySlots) copySlots = []; - copySlots.forEach(function(slot) { child[slot] = parent[slot] }); - return [parent, child]; + var ret = parents.slice(0); + for (var i = 0; i < parents.length; i++) { + var parent = parents[i]; + var child = parent[childSlot]; + parent[childSlot] = null; + child.parentUid = parent.__uid__; + child.parentSlot = childSlot; + child.lineNum = parent.lineNum; // Debugging + copySlots.forEach(function(slot) { child[slot] = parent[slot] }); + ret.push(child); + } + return ret; }, }; } |