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

Side by Side Diff: src/scopes.cc

Issue 113393: Optimize the scope creation code by lazily allocating the hash maps... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scopes.h ('k') | src/utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // ---------------------------------------------------------------------------- 105 // ----------------------------------------------------------------------------
106 // Implementation of Scope 106 // Implementation of Scope
107 107
108 108
109 // Dummy constructor 109 // Dummy constructor
110 Scope::Scope() 110 Scope::Scope()
111 : inner_scopes_(0), 111 : inner_scopes_(0),
112 locals_(false), 112 locals_(false),
113 temps_(0), 113 temps_(0),
114 params_(0), 114 params_(0),
115 dynamics_(false), 115 dynamics_(NULL),
116 dynamics_local_(false),
117 dynamics_global_(false),
118 unresolved_(0), 116 unresolved_(0),
119 decls_(0) { 117 decls_(0) {
120 } 118 }
121 119
122 120
123 Scope::Scope(Scope* outer_scope, Type type) 121 Scope::Scope(Scope* outer_scope, Type type)
124 : outer_scope_(outer_scope), 122 : outer_scope_(outer_scope),
125 inner_scopes_(4), 123 inner_scopes_(4),
126 type_(type), 124 type_(type),
127 scope_name_(Factory::empty_symbol()), 125 scope_name_(Factory::empty_symbol()),
128 locals_(),
129 temps_(4), 126 temps_(4),
130 params_(4), 127 params_(4),
128 dynamics_(NULL),
131 unresolved_(16), 129 unresolved_(16),
132 decls_(4), 130 decls_(4),
133 receiver_(NULL), 131 receiver_(NULL),
134 function_(NULL), 132 function_(NULL),
135 arguments_(NULL), 133 arguments_(NULL),
136 arguments_shadow_(NULL), 134 arguments_shadow_(NULL),
137 illegal_redecl_(NULL), 135 illegal_redecl_(NULL),
138 scope_inside_with_(false), 136 scope_inside_with_(false),
139 scope_contains_with_(false), 137 scope_contains_with_(false),
140 scope_calls_eval_(false), 138 scope_calls_eval_(false),
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 468
471 Indent(n1, "// temporary vars\n"); 469 Indent(n1, "// temporary vars\n");
472 for (int i = 0; i < temps_.length(); i++) { 470 for (int i = 0; i < temps_.length(); i++) {
473 PrintVar(&printer, n1, temps_[i]); 471 PrintVar(&printer, n1, temps_[i]);
474 } 472 }
475 473
476 Indent(n1, "// local vars\n"); 474 Indent(n1, "// local vars\n");
477 PrintMap(&printer, n1, &locals_); 475 PrintMap(&printer, n1, &locals_);
478 476
479 Indent(n1, "// dynamic vars\n"); 477 Indent(n1, "// dynamic vars\n");
480 PrintMap(&printer, n1, &dynamics_); 478 if (dynamics_ != NULL) {
481 PrintMap(&printer, n1, &dynamics_local_); 479 PrintMap(&printer, n1, dynamics_->GetMap(Variable::DYNAMIC));
482 PrintMap(&printer, n1, &dynamics_global_); 480 PrintMap(&printer, n1, dynamics_->GetMap(Variable::DYNAMIC_LOCAL));
481 PrintMap(&printer, n1, dynamics_->GetMap(Variable::DYNAMIC_GLOBAL));
482 }
483 483
484 // Print inner scopes (disable by providing negative n). 484 // Print inner scopes (disable by providing negative n).
485 if (n >= 0) { 485 if (n >= 0) {
486 for (int i = 0; i < inner_scopes_.length(); i++) { 486 for (int i = 0; i < inner_scopes_.length(); i++) {
487 PrintF("\n"); 487 PrintF("\n");
488 inner_scopes_[i]->Print(n1); 488 inner_scopes_[i]->Print(n1);
489 } 489 }
490 } 490 }
491 491
492 Indent(n0, "}\n"); 492 Indent(n0, "}\n");
493 } 493 }
494 #endif // DEBUG 494 #endif // DEBUG
495 495
496 496
497 Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) { 497 Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) {
498 // Space optimization: reuse existing non-local with the same name 498 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart();
499 // and mode. 499 LocalsMap* map = dynamics_->GetMap(mode);
500 LocalsMap* map = NULL;
501 switch (mode) {
502 case Variable::DYNAMIC:
503 map = &dynamics_;
504 break;
505 case Variable::DYNAMIC_LOCAL:
506 map = &dynamics_local_;
507 break;
508 case Variable::DYNAMIC_GLOBAL:
509 map = &dynamics_global_;
510 break;
511 default:
512 UNREACHABLE();
513 break;
514 }
515 Variable* var = map->Lookup(name); 500 Variable* var = map->Lookup(name);
516 if (var == NULL) { 501 if (var == NULL) {
517 // Declare a new non-local. 502 // Declare a new non-local.
518 var = map->Declare(NULL, name, mode, true, false); 503 var = map->Declare(NULL, name, mode, true, false);
519 // Allocate it by giving it a dynamic lookup. 504 // Allocate it by giving it a dynamic lookup.
520 var->rewrite_ = new Slot(var, Slot::LOOKUP, -1); 505 var->rewrite_ = new Slot(var, Slot::LOOKUP, -1);
521 } 506 }
522 return var; 507 return var;
523 } 508 }
524 509
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 929 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
945 !must_have_local_context) { 930 !must_have_local_context) {
946 num_heap_slots_ = 0; 931 num_heap_slots_ = 0;
947 } 932 }
948 933
949 // Allocation done. 934 // Allocation done.
950 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 935 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
951 } 936 }
952 937
953 } } // namespace v8::internal 938 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698