Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: src/ast/scopes.cc

Issue 2159573002: Turn the unresolved-references list into a linked list using the VariableProxies themselves (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comment Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index e12c2f9b3ce9ba2b2d94c8854abae1e6b401c6b4..f003f8c37a148a9d56b74507a925a9ea7b610a70 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -88,7 +88,7 @@ Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
variables_(zone),
temps_(4, zone),
params_(4, zone),
- unresolved_(16, zone),
+ unresolved_(nullptr),
decls_(4, zone),
module_descriptor_(scope_type == MODULE_SCOPE ? new (zone)
ModuleDescriptor(zone)
@@ -109,7 +109,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
variables_(zone),
temps_(4, zone),
params_(4, zone),
- unresolved_(16, zone),
adamk 2016/07/18 16:54:34 I wonder if it was this 16 that was causing excess
+ unresolved_(nullptr),
decls_(4, zone),
module_descriptor_(NULL),
sloppy_block_function_map_(zone),
@@ -133,7 +133,7 @@ Scope::Scope(Zone* zone, Scope* inner_scope,
variables_(zone),
temps_(0, zone),
params_(0, zone),
- unresolved_(0, zone),
+ unresolved_(nullptr),
decls_(0, zone),
module_descriptor_(NULL),
sloppy_block_function_map_(zone),
@@ -353,8 +353,15 @@ Scope* Scope::FinalizeBlockScope() {
}
// Move unresolved variables
- for (int i = 0; i < unresolved_.length(); i++) {
- outer_scope()->unresolved_.Add(unresolved_[i], zone());
+ VariableProxy* unresolved = unresolved_;
+ if (outer_scope()->unresolved_ == nullptr) {
+ outer_scope()->unresolved_ = unresolved;
+ } else if (unresolved != nullptr) {
+ while (unresolved->next_unresolved() != nullptr) {
+ unresolved = unresolved->next_unresolved();
+ }
+ unresolved->set_next_unresolved(outer_scope()->unresolved_);
+ outer_scope()->unresolved_ = unresolved_;
}
PropagateUsageFlagsToScope(outer_scope_);
@@ -529,13 +536,20 @@ Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) {
bool Scope::RemoveUnresolved(VariableProxy* var) {
- // Most likely (always?) any variable we want to remove
- // was just added before, so we search backwards.
- for (int i = unresolved_.length(); i-- > 0;) {
- if (unresolved_[i] == var) {
- unresolved_.Remove(i);
+ if (unresolved_ == var) {
+ unresolved_ = var->next_unresolved();
+ var->set_next_unresolved(nullptr);
+ return true;
+ }
+ VariableProxy* current = unresolved_;
+ while (current != nullptr) {
+ VariableProxy* next = current->next_unresolved();
+ if (var == next) {
+ current->set_next_unresolved(next->next_unresolved());
+ var->set_next_unresolved(nullptr);
return true;
}
+ current = next;
}
return false;
}
@@ -822,8 +836,8 @@ Handle<StringSet> Scope::CollectNonLocals(Handle<StringSet> non_locals) {
// Collect non-local variables referenced in the scope.
// TODO(yangguo): store non-local variables explicitly if we can no longer
// rely on unresolved_ to find them.
- for (int i = 0; i < unresolved_.length(); i++) {
- VariableProxy* proxy = unresolved_[i];
+ for (VariableProxy* proxy = unresolved_; proxy != nullptr;
+ proxy = proxy->next_unresolved()) {
if (proxy->is_resolved() && proxy->var()->IsStackAllocated()) continue;
Handle<String> name = proxy->name();
non_locals = StringSet::Add(non_locals, name);
@@ -1218,8 +1232,9 @@ bool Scope::ResolveVariablesRecursively(ParseInfo* info,
DCHECK(info->script_scope()->is_script_scope());
// Resolve unresolved variables for this scope.
- for (int i = 0; i < unresolved_.length(); i++) {
- if (!ResolveVariable(info, unresolved_[i], factory)) return false;
+ for (VariableProxy* proxy = unresolved_; proxy != nullptr;
+ proxy = proxy->next_unresolved()) {
+ if (!ResolveVariable(info, proxy, factory)) return false;
}
// Resolve unresolved variables for inner scopes.
« no previous file with comments | « src/ast/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698