aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-21 13:04:56 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-21 13:04:56 -0800
commitcbb0b5920855b0d5353966cb2f87f797a37060e5 (patch)
treeea5bfd3d6b754e2aa5b226e2b6c8b2c39443316f /tools/js-optimizer.js
parent19a38d059bd6da1402edd3dc13c8485025059fa7 (diff)
parent7a8c26b65f906de5f7490311e89eb6d5bf722211 (diff)
Merge pull request #2039 from rfk/rfk/minify-loop-labels
Minify loop labels while we're minifying local names.
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index d604f546..98cb4c49 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -2870,7 +2870,6 @@ function minifyLocals(ast) {
}
});
- // Traverse and minify all names.
// The first time we encounter a local name, we assign it a
// minified name that's not currently in use. Allocating on
// demand means they're processed in a predicatable order,
@@ -2887,6 +2886,17 @@ function minifyLocals(ast) {
}
}
}
+
+ // We can also minify loop labels, using a separate namespace
+ // to the variable declarations.
+ var newLabels = {};
+ var nextMinifiedLabel = 0;
+ function getNextMinifiedLabel() {
+ ensureMinifiedNames(nextMinifiedLabel);
+ return minifiedNames[nextMinifiedLabel++];
+ }
+
+ // Traverse and minify all names.
if (fun[1] in extraInfo.globals) {
fun[1] = extraInfo.globals[fun[1]];
assert(fun[1]);
@@ -2917,6 +2927,15 @@ function minifyLocals(ast) {
}
defn[0] = newNames[name];
});
+ } else if (type === 'label') {
+ if (!newLabels[node[1]]) {
+ newLabels[node[1]] = getNextMinifiedLabel();
+ }
+ node[1] = newLabels[node[1]];
+ } else if (type === 'break' || type === 'continue') {
+ if (node[1]) {
+ node[1] = newLabels[node[1]];
+ }
}
});