Chromium Code Reviews| Index: src/ast/scopes.cc |
| diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc |
| index 5b91bb6b7edee3be392a05077e73537a448a2a2c..b019276bee8b56acb7b117d9f5836ed6ff5e8aca 100644 |
| --- a/src/ast/scopes.cc |
| +++ b/src/ast/scopes.cc |
| @@ -558,17 +558,19 @@ Variable* Scope::NewTemporary(const AstRawString* name) { |
| return var; |
| } |
| - |
| -bool Scope::RemoveTemporary(Variable* var) { |
| +int Scope::RemoveTemporary(Variable* var) { |
| + DCHECK_NOT_NULL(var); |
| // Most likely (always?) any temporary variable we want to remove |
| // was just added before, so we search backwards. |
| for (int i = temps_.length(); i-- > 0;) { |
| if (temps_[i] == var) { |
| - temps_.Remove(i); |
| - return true; |
| + // Don't shrink temps_, as callers of this method expect |
| + // the returned indices to be unique per-scope. |
| + temps_[i] = nullptr; |
| + return i; |
| } |
| } |
| - return false; |
| + return -1; |
| } |
| @@ -635,6 +637,7 @@ void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, |
| // context as a whole has forced context allocation. |
| for (int i = 0; i < temps_.length(); i++) { |
| Variable* var = temps_[i]; |
| + if (var == nullptr) continue; |
| if (var->is_used()) { |
| if (var->IsContextSlot()) { |
| DCHECK(has_forced_context_allocation()); |
| @@ -986,7 +989,9 @@ void Scope::Print(int n) { |
| if (temps_.length() > 0) { |
|
nickie
2016/05/10 13:47:08
If you have length() > 0 but only null elements, y
adamk
2016/05/10 17:36:11
This is probably the ugliest part of this approach
|
| Indent(n1, "// temporary vars:\n"); |
| for (int i = 0; i < temps_.length(); i++) { |
| - PrintVar(n1, temps_[i]); |
| + if (temps_[i] != NULL) { |
|
nickie
2016/05/10 13:47:08
Not nullptr? :-)
adamk
2016/05/10 17:36:11
Was going for consistent, but looks like this func
|
| + PrintVar(n1, temps_[i]); |
| + } |
| } |
| } |
| @@ -1416,6 +1421,7 @@ void Scope::AllocateDeclaredGlobal(Isolate* isolate, Variable* var) { |
| void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { |
| // All variables that have no rewrite yet are non-parameter locals. |
| for (int i = 0; i < temps_.length(); i++) { |
| + if (temps_[i] == nullptr) continue; |
| AllocateNonParameterLocal(isolate, temps_[i]); |
| } |