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

Unified Diff: src/scopeinfo.cc

Issue 1281883002: Group lexical context variables for faster look up. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: added comments and TODOs Created 5 years, 4 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/runtime/runtime-scopes.cc ('k') | src/scopes.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopeinfo.cc
diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc
index e490fd9ce48f11eff84aa20f143f852dfea3d7ac..9fb88e4e232e1153e07939dba55d55c1a3e60ca2 100644
--- a/src/scopeinfo.cc
+++ b/src/scopeinfo.cc
@@ -149,6 +149,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
// Add context locals' info.
DCHECK(index == scope_info->ContextLocalInfoEntriesIndex());
+ bool encountered_lexical = false;
+ int lexical_context_local_count = 0;
for (int i = 0; i < context_local_count; ++i) {
Variable* var = context_locals[i];
uint32_t value =
@@ -156,8 +158,16 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
ContextLocalInitFlag::encode(var->initialization_flag()) |
ContextLocalMaybeAssignedFlag::encode(var->maybe_assigned());
scope_info->set(index++, Smi::FromInt(value));
+ if (encountered_lexical) {
+ // Check that context locals are sorted so that lexicals are at the end.
+ DCHECK(IsLexicalVariableMode(var->mode()));
+ } else if (IsLexicalVariableMode(var->mode())) {
+ lexical_context_local_count = context_local_count - i;
+ }
}
+ scope_info->SetLexicalContextLocalCount(lexical_context_local_count);
+
// Add context globals' info.
DCHECK(index == scope_info->ContextGlobalInfoEntriesIndex());
for (int i = 0; i < context_global_count; ++i) {
@@ -222,6 +232,7 @@ Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) {
const int stack_local_count = 0;
const int context_local_count = 1;
+ const int lexical_context_local_count = 1;
const int context_global_count = 0;
const int strong_mode_free_variable_count = 0;
const bool simple_parameter_list = true;
@@ -254,6 +265,7 @@ Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) {
scope_info->SetParameterCount(parameter_count);
scope_info->SetStackLocalCount(stack_local_count);
scope_info->SetContextLocalCount(context_local_count);
+ scope_info->SetLexicalContextLocalCount(lexical_context_local_count);
scope_info->SetContextGlobalCount(context_global_count);
scope_info->SetStrongModeFreeVariableCount(strong_mode_free_variable_count);
@@ -572,6 +584,31 @@ int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info,
}
+int ScopeInfo::LexicalContextSlotIndex(Handle<ScopeInfo> scope_info,
+ Handle<String> name) {
+ DCHECK(name->IsInternalizedString());
+ if (scope_info->length() > 0) {
+ // TODO(yangguo): consider using the context slot cache here.
+ int total_count = scope_info->ContextLocalCount();
+ int lexical_count = scope_info->LexicalContextLocalCount();
+ int non_lexical_count = total_count - lexical_count;
+
+ int start = scope_info->ContextLocalNameEntriesIndex();
+ int end = start + total_count;
+ int lexical_start = start + non_lexical_count;
+
+ for (int i = lexical_start; i < end; ++i) {
+ if (*name == scope_info->get(i)) {
+ int var = i - start;
+ DCHECK(IsLexicalVariableMode(scope_info->ContextLocalMode(var)));
+ return Context::MIN_CONTEXT_SLOTS + var;
+ }
+ }
+ }
+ return -1;
+}
+
+
String* ScopeInfo::ContextSlotName(int slot_index) {
int const var = slot_index - Context::MIN_CONTEXT_SLOTS;
DCHECK_LE(0, var);
« no previous file with comments | « src/runtime/runtime-scopes.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698