&& !self.uses_eval
) {
var in_use = [];
+ var in_use_ids = {}; // avoid expensive linear scans of in_use
var initializations = new Dictionary();
// pass 1: find out which symbols are directly used in
// this scope (not in nested scopes).
return true;
}
if (node instanceof AST_SymbolRef) {
- push_uniq(in_use, node.definition());
+ var node_def = node.definition();
+ if (!(node_def.id in in_use_ids)) {
+ in_use_ids[node_def.id] = true;
+ in_use.push(node_def);
+ }
return true;
}
if (node instanceof AST_Scope) {
if (init) init.forEach(function(init){
var tw = new TreeWalker(function(node){
if (node instanceof AST_SymbolRef) {
- push_uniq(in_use, node.definition());
+ var node_def = node.definition();
+ if (!(node_def.id in in_use_ids)) {
+ in_use_ids[node_def.id] = true;
+ in_use.push(node_def);
+ }
}
});
init.walk(tw);
}
}
if (node instanceof AST_Defun && node !== self) {
- if (!member(node.name.definition(), in_use)) {
+ if (!(node.name.definition().id in in_use_ids)) {
compressor.warn("Dropping unused function {name} [{file}:{line},{col}]", {
name : node.name.name,
file : node.name.start.file,
}
if (node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn)) {
var def = node.definitions.filter(function(def){
- if (member(def.name.definition(), in_use)) return true;
+ if (def.name.definition().id in in_use_ids) return true;
var w = {
name : def.name.name,
file : def.name.start.file,