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

Side by Side Diff: src/scopes.h

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/objects.cc ('k') | src/scopes.cc » ('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 17 matching lines...) Expand all
28 #ifndef V8_SCOPES_H_ 28 #ifndef V8_SCOPES_H_
29 #define V8_SCOPES_H_ 29 #define V8_SCOPES_H_
30 30
31 #include "ast.h" 31 #include "ast.h"
32 #include "hashmap.h" 32 #include "hashmap.h"
33 33
34 namespace v8 { namespace internal { 34 namespace v8 { namespace internal {
35 35
36 36
37 // A hash map to support fast local variable declaration and lookup. 37 // A hash map to support fast local variable declaration and lookup.
38
39 class LocalsMap: public HashMap { 38 class LocalsMap: public HashMap {
40 public: 39 public:
41 LocalsMap(); 40 LocalsMap();
42 41
43 // Dummy constructor. This constructor doesn't set up the map 42 // Dummy constructor. This constructor doesn't set up the map
44 // properly so don't use it unless you have a good reason. 43 // properly so don't use it unless you have a good reason.
45 explicit LocalsMap(bool gotta_love_static_overloading); 44 explicit LocalsMap(bool gotta_love_static_overloading);
46 45
47 virtual ~LocalsMap(); 46 virtual ~LocalsMap();
48 47
49 Variable* Declare(Scope* scope, Handle<String> name, Variable::Mode mode, 48 Variable* Declare(Scope* scope, Handle<String> name, Variable::Mode mode,
50 bool is_valid_LHS, bool is_this); 49 bool is_valid_LHS, bool is_this);
51 50
52 Variable* Lookup(Handle<String> name); 51 Variable* Lookup(Handle<String> name);
53 }; 52 };
54 53
55 54
55 // The dynamic scope part holds hash maps for the variables that will
56 // be looked up dynamically from within eval and with scopes. The objects
57 // are allocated on-demand from Scope::NonLocal to avoid wasting memory
58 // and setup time for scopes that don't need them.
59 class DynamicScopePart : public ZoneObject {
60 public:
61 LocalsMap* GetMap(Variable::Mode mode) {
62 int index = mode - Variable::DYNAMIC;
63 ASSERT(index >= 0 && index < 3);
64 return &maps_[index];
65 }
66
67 private:
68 LocalsMap maps_[3];
69 };
70
71
56 // Global invariants after AST construction: Each reference (i.e. identifier) 72 // Global invariants after AST construction: Each reference (i.e. identifier)
57 // to a JavaScript variable (including global properties) is represented by a 73 // to a JavaScript variable (including global properties) is represented by a
58 // VariableProxy node. Immediately after AST construction and before variable 74 // VariableProxy node. Immediately after AST construction and before variable
59 // allocation, most VariableProxy nodes are "unresolved", i.e. not bound to a 75 // allocation, most VariableProxy nodes are "unresolved", i.e. not bound to a
60 // corresponding variable (though some are bound during parse time). Variable 76 // corresponding variable (though some are bound during parse time). Variable
61 // allocation binds each unresolved VariableProxy to one Variable and assigns 77 // allocation binds each unresolved VariableProxy to one Variable and assigns
62 // a location. Note that many VariableProxy nodes may refer to the same Java- 78 // a location. Note that many VariableProxy nodes may refer to the same Java-
63 // Script variable. 79 // Script variable.
64 80
65 class Scope: public ZoneObject { 81 class Scope: public ZoneObject {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 Handle<String> scope_name_; 287 Handle<String> scope_name_;
272 288
273 // The variables declared in this scope: 289 // The variables declared in this scope:
274 // all user-declared variables (incl. parameters) 290 // all user-declared variables (incl. parameters)
275 LocalsMap locals_; 291 LocalsMap locals_;
276 // compiler-allocated (user-invisible) temporaries 292 // compiler-allocated (user-invisible) temporaries
277 ZoneList<Variable*> temps_; 293 ZoneList<Variable*> temps_;
278 // parameter list in source order 294 // parameter list in source order
279 ZoneList<Variable*> params_; 295 ZoneList<Variable*> params_;
280 // variables that must be looked up dynamically 296 // variables that must be looked up dynamically
281 LocalsMap dynamics_; 297 DynamicScopePart* dynamics_;
282 LocalsMap dynamics_local_;
283 LocalsMap dynamics_global_;
284 // unresolved variables referred to from this scope 298 // unresolved variables referred to from this scope
285 ZoneList<VariableProxy*> unresolved_; 299 ZoneList<VariableProxy*> unresolved_;
286 // declarations 300 // declarations
287 ZoneList<Declaration*> decls_; 301 ZoneList<Declaration*> decls_;
288 // convenience variable 302 // convenience variable
289 VariableProxy* receiver_; 303 VariableProxy* receiver_;
290 // function variable, if any; function scopes only 304 // function variable, if any; function scopes only
291 Variable* function_; 305 Variable* function_;
292 // convenience variable; function scopes only 306 // convenience variable; function scopes only
293 VariableProxy* arguments_; 307 VariableProxy* arguments_;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) { 373 virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) {
360 return NULL; 374 return NULL;
361 } 375 }
362 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; } 376 virtual VariableProxy* NewTemporary(Handle<String> name) { return NULL; }
363 }; 377 };
364 378
365 379
366 } } // namespace v8::internal 380 } } // namespace v8::internal
367 381
368 #endif // V8_SCOPES_H_ 382 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698