AdvancedOptimizer.prototype.reduceSimpleNonAdjacentCases = function (tokens, repeated, candidates) {
var reduced = false;
+ function filterOut(idx, bodies) {
+ return data[idx].isPartial && bodies.length === 0;
+ }
+
+ function reduceBody(token, newBody, processedCount, tokenIdx) {
+ if (!data[processedCount - tokenIdx - 1].isPartial) {
+ changeBodyOf(token, newBody);
+ reduced = true;
+ }
+ }
+
for (var i = 0, l = repeated.length; i < l; i++) {
var selector = repeated[i];
var data = candidates[selector];
- /* jshint loopfunc: true */
this.reduceSelector(tokens, selector, data, {
- filterOut: function (idx, bodies) {
- return data[idx].isPartial && bodies.length === 0;
- },
- callback: function (token, newBody, processedCount, tokenIdx) {
- if (!data[processedCount - tokenIdx - 1].isPartial) {
- changeBodyOf(token, newBody);
- reduced = true;
- }
- }
+ filterOut: filterOut,
+ callback: reduceBody
});
}
AdvancedOptimizer.prototype.reduceComplexNonAdjacentCases = function (tokens, candidates) {
var reduced = false;
+ var localContext = {};
+
+ function filterOut(idx) {
+ return localContext.data[idx].where < localContext.intoPosition;
+ }
+
+ function collectReducedBodies(token, newBody, processedCount, tokenIdx) {
+ if (tokenIdx === 0)
+ localContext.reducedBodies.push(newBody);
+ }
allSelectors:
for (var complexSelector in candidates) {
var intoPosition = into[into.length - 1].where;
var intoToken = tokens[intoPosition];
+ var reducedBodies = [];
var selectors = this.isSpecial(complexSelector) ?
[complexSelector] :
into[0].list;
- var reducedBodies = [];
+
+ localContext.intoPosition = intoPosition;
+ localContext.reducedBodies = reducedBodies;
for (var j = 0, m = selectors.length; j < m; j++) {
var selector = selectors[j];
if (data.length < 2)
continue allSelectors;
- /* jshint loopfunc: true */
+ localContext.data = data;
+
this.reduceSelector(tokens, selector, data, {
- filterOut: function (idx) {
- return data[idx].where < intoPosition;
- },
- callback: function (token, newBody, processedCount, tokenIdx) {
- if (tokenIdx === 0)
- reducedBodies.push(newBody);
- }
+ filterOut: filterOut,
+ callback: collectReducedBodies
});
if (reducedBodies[reducedBodies.length - 1].list.length != reducedBodies[0].list.length)