Author: [email protected]
Date: Thu May 14 00:12:58 2009
New Revision: 1942

Modified:
    branches/bleeding_edge/src/hashmap.cc
    branches/bleeding_edge/src/objects.cc
    branches/bleeding_edge/src/scopes.cc
    branches/bleeding_edge/src/scopes.h
    branches/bleeding_edge/src/utils.h

Log:
Optimize the scope creation code by lazily allocating the hash maps
for dynamic variables (only do it for the scopes that need them).
Review URL: http://codereview.chromium.org/113393

Modified: branches/bleeding_edge/src/hashmap.cc
==============================================================================
--- branches/bleeding_edge/src/hashmap.cc       (original)
+++ branches/bleeding_edge/src/hashmap.cc       Thu May 14 00:12:58 2009
@@ -31,13 +31,6 @@

  namespace v8 { namespace internal {

-
-static inline bool IsPowerOf2(uint32_t x) {
-  ASSERT(x != 0);
-  return (x & (x - 1)) == 0;
-}
-
-
  Allocator HashMap::DefaultAllocator;



Modified: branches/bleeding_edge/src/objects.cc
==============================================================================
--- branches/bleeding_edge/src/objects.cc       (original)
+++ branches/bleeding_edge/src/objects.cc       Thu May 14 00:12:58 2009
@@ -3437,8 +3437,8 @@


  void  
SeqTwoByteString::SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* rbb,
-                                                     unsigned* offset_ptr,
-                                                     unsigned max_chars) {
+                                                           unsigned*  
offset_ptr,
+                                                           unsigned  
max_chars) {
    unsigned chars_read = 0;
    unsigned offset = *offset_ptr;
    while (chars_read < max_chars) {

Modified: branches/bleeding_edge/src/scopes.cc
==============================================================================
--- branches/bleeding_edge/src/scopes.cc        (original)
+++ branches/bleeding_edge/src/scopes.cc        Thu May 14 00:12:58 2009
@@ -112,9 +112,7 @@
      locals_(false),
      temps_(0),
      params_(0),
-    dynamics_(false),
-    dynamics_local_(false),
-    dynamics_global_(false),
+    dynamics_(NULL),
      unresolved_(0),
      decls_(0) {
  }
@@ -125,9 +123,9 @@
      inner_scopes_(4),
      type_(type),
      scope_name_(Factory::empty_symbol()),
-    locals_(),
      temps_(4),
      params_(4),
+    dynamics_(NULL),
      unresolved_(16),
      decls_(4),
      receiver_(NULL),
@@ -477,9 +475,11 @@
    PrintMap(&printer, n1, &locals_);

    Indent(n1, "// dynamic vars\n");
-  PrintMap(&printer, n1, &dynamics_);
-  PrintMap(&printer, n1, &dynamics_local_);
-  PrintMap(&printer, n1, &dynamics_global_);
+  if (dynamics_ != NULL) {
+    PrintMap(&printer, n1, dynamics_->GetMap(Variable::DYNAMIC));
+    PrintMap(&printer, n1, dynamics_->GetMap(Variable::DYNAMIC_LOCAL));
+    PrintMap(&printer, n1, dynamics_->GetMap(Variable::DYNAMIC_GLOBAL));
+  }

    // Print inner scopes (disable by providing negative n).
    if (n >= 0) {
@@ -495,23 +495,8 @@


  Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) {
-  // Space optimization: reuse existing non-local with the same name
-  // and mode.
-  LocalsMap* map = NULL;
-  switch (mode) {
-    case Variable::DYNAMIC:
-      map = &dynamics_;
-      break;
-    case Variable::DYNAMIC_LOCAL:
-      map = &dynamics_local_;
-      break;
-    case Variable::DYNAMIC_GLOBAL:
-      map = &dynamics_global_;
-      break;
-    default:
-      UNREACHABLE();
-      break;
-  }
+  if (dynamics_ == NULL) dynamics_ = new DynamicScopePart();
+  LocalsMap* map = dynamics_->GetMap(mode);
    Variable* var = map->Lookup(name);
    if (var == NULL) {
      // Declare a new non-local.

Modified: branches/bleeding_edge/src/scopes.h
==============================================================================
--- branches/bleeding_edge/src/scopes.h (original)
+++ branches/bleeding_edge/src/scopes.h Thu May 14 00:12:58 2009
@@ -35,7 +35,6 @@


  // A hash map to support fast local variable declaration and lookup.
-
  class LocalsMap: public HashMap {
   public:
    LocalsMap();
@@ -53,6 +52,23 @@
  };


+// The dynamic scope part holds hash maps for the variables that will
+// be looked up dynamically from within eval and with scopes. The objects
+// are allocated on-demand from Scope::NonLocal to avoid wasting memory
+// and setup time for scopes that don't need them.
+class DynamicScopePart : public ZoneObject {
+ public:
+  LocalsMap* GetMap(Variable::Mode mode) {
+    int index = mode - Variable::DYNAMIC;
+    ASSERT(index >= 0 && index < 3);
+    return &maps_[index];
+  }
+
+ private:
+  LocalsMap maps_[3];
+};
+
+
  // Global invariants after AST construction: Each reference (i.e.  
identifier)
  // to a JavaScript variable (including global properties) is represented  
by a
  // VariableProxy node. Immediately after AST construction and before  
variable
@@ -278,9 +294,7 @@
    // parameter list in source order
    ZoneList<Variable*> params_;
    // variables that must be looked up dynamically
-  LocalsMap dynamics_;
-  LocalsMap dynamics_local_;
-  LocalsMap dynamics_global_;
+  DynamicScopePart* dynamics_;
    // unresolved variables referred to from this scope
    ZoneList<VariableProxy*> unresolved_;
    // declarations

Modified: branches/bleeding_edge/src/utils.h
==============================================================================
--- branches/bleeding_edge/src/utils.h  (original)
+++ branches/bleeding_edge/src/utils.h  Thu May 14 00:12:58 2009
@@ -42,8 +42,6 @@
  }


-
-
  // The C++ standard leaves the semantics of '>>' undefined for
  // negative signed operands. Most implementations do the right thing,
  // though.

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to