aboutsummaryrefslogtreecommitdiff
path: root/src/analyzer.js
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-10-16 15:33:19 -0700
committeralon@honor <none@none>2010-10-16 15:33:19 -0700
commit373e75c2151229ae4b6caaae77eb9d49da72e2c2 (patch)
tree6297cdad2fa5c916b25768cdef99807e44f3ca72 /src/analyzer.js
parent6fa5f7160c816fc982432dc5f990a1da14d09175 (diff)
optimize out unneeded loops in |multiple| blocks
Diffstat (limited to 'src/analyzer.js')
-rw-r--r--src/analyzer.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 6c062b82..30512b45 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -353,6 +353,7 @@ function analyzer(data) {
}
}
+ //! @param toLabelId If false, just a dry run - useful to search for labels
function replaceLabels(line, labelIds, toLabelId) {
var ret = [];
@@ -362,18 +363,22 @@ function analyzer(data) {
var wildcardParts = null;
if (wildcard) {
wildcardParts = value.split('|');
- assert(wildcardParts[1] == '*'); // For now, just handle that case
}
function wildcardCheck(s) {
var parts = s.split('|');
- return wildcardParts[0] == parts[0] && wildcardParts[2] == parts[2];
+ for (var i = 0; i < 3; i++) {
+ if (wildcardParts[i] !== '*' && wildcardParts[i] != parts[i]) return false;
+ }
+ return true;
}
operateOnLabels(line, function process(item, id) {
if (item[id] in labelIds || (wildcard && wildcardCheck(item[id]))) {
ret.push(item[id]);
dprint('relooping', 'zz ' + id + ' replace ' + item[id] + ' with ' + toLabelId);
- item[id] = toLabelId + '|' + item[id];
+ if (toLabelId) {
+ item[id] = toLabelId + '|' + item[id];
+ }
}
});
return ret;
@@ -769,6 +774,13 @@ function analyzer(data) {
}
recurseBlock(block, optimizeBlock);
+
+ if (block.type === 'multiple') {
+ // Check if the one-time loop (that allows breaking out) is actually needed
+ if (replaceLabelLabels(block.labels, set('BREAK|' + block.entries[0] + '|*')).length === 0) {
+ block.loopless = true;
+ }
+ }
}
// TODO: Parallelize