Revision: 20960
Author:   [email protected]
Date:     Fri Apr 25 08:18:24 2014 UTC
Log:      HashTable::EnsureCapacity() handlified.

[email protected]

Review URL: https://codereview.chromium.org/250643002
http://code.google.com/p/v8/source/detail?r=20960

Modified:
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h

=======================================
--- /branches/bleeding_edge/src/objects.cc      Fri Apr 25 08:10:44 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Fri Apr 25 08:18:24 2014 UTC
@@ -14677,7 +14677,9 @@


 template<typename Derived, typename Shape, typename Key>
-void HashTable<Derived, Shape, Key>::Rehash(Derived* new_table, Key key) {
+void HashTable<Derived, Shape, Key>::Rehash(
+    Handle<Derived> new_table,
+    Key key) {
   ASSERT(NumberOfElements() < new_table->Capacity());

   DisallowHeapAllocation no_gc;
@@ -14779,49 +14781,35 @@


 template<typename Derived, typename Shape, typename Key>
-MaybeObject* HashTable<Derived, Shape, Key>::EnsureCapacity(
+Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
+    Handle<Derived> table,
     int n,
     Key key,
     PretenureFlag pretenure) {
-  int capacity = Capacity();
-  int nof = NumberOfElements() + n;
-  int nod = NumberOfDeletedElements();
+  Isolate* isolate = table->GetIsolate();
+  int capacity = table->Capacity();
+  int nof = table->NumberOfElements() + n;
+  int nod = table->NumberOfDeletedElements();
   // Return if:
   //   50% is still free after adding n elements and
   //   at most 50% of the free elements are deleted elements.
   if (nod <= (capacity - nof) >> 1) {
     int needed_free = nof >> 1;
-    if (nof + needed_free <= capacity) return this;
+    if (nof + needed_free <= capacity) return table;
   }

   const int kMinCapacityForPretenure = 256;
   bool should_pretenure = pretenure == TENURED ||
- ((capacity > kMinCapacityForPretenure) && !GetHeap()->InNewSpace(this));
-  Object* obj;
-  { MaybeObject* maybe_obj =
-        Allocate(GetHeap(),
-                 nof * 2,
-                 USE_DEFAULT_MINIMUM_CAPACITY,
-                 should_pretenure ? TENURED : NOT_TENURED);
-    if (!maybe_obj->ToObject(&obj)) return maybe_obj;
-  }
-
-  Rehash(Derived::cast(obj), key);
-  return Derived::cast(obj);
-}
-
+      ((capacity > kMinCapacityForPretenure) &&
+          !isolate->heap()->InNewSpace(*table));
+  Handle<Derived> new_table = HashTable::New(
+      isolate,
+      nof * 2,
+      USE_DEFAULT_MINIMUM_CAPACITY,
+      should_pretenure ? TENURED : NOT_TENURED);

-template<typename Derived, typename Shape, typename Key>
-Handle<Derived> HashTable<Derived, Shape, Key>::EnsureCapacity(
-    Handle<Derived> table,
-    int n,
-    Key key,
-    PretenureFlag pretenure) {
-  Isolate* isolate = table->GetIsolate();
-  CALL_HEAP_FUNCTION(
-      isolate,
-      static_cast<HashTable*>(*table)->EnsureCapacity(n, key, pretenure),
-      Derived);
+  table->Rehash(new_table, key);
+  return new_table;
 }


@@ -14846,13 +14834,13 @@
   bool pretenure =
       (at_least_room_for > kMinCapacityForPretenure) &&
       !isolate->heap()->InNewSpace(*table);
-  Handle<Derived> new_table = New(
+  Handle<Derived> new_table = HashTable::New(
       isolate,
       at_least_room_for,
       USE_DEFAULT_MINIMUM_CAPACITY,
       pretenure ? TENURED : NOT_TENURED);

-  table->Rehash(*new_table, key);
+  table->Rehash(new_table, key);
   return new_table;
 }

=======================================
--- /branches/bleeding_edge/src/objects.h       Fri Apr 25 08:10:44 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Fri Apr 25 08:18:24 2014 UTC
@@ -3736,7 +3736,7 @@
       PretenureFlag pretenure = NOT_TENURED);

   // Returns a new HashTable object.
-  static Handle<Derived> New(
+  MUST_USE_RESULT static Handle<Derived> New(
       Isolate* isolate,
       int at_least_space_for,
       MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY,
@@ -3842,30 +3842,27 @@
       uint32_t last, uint32_t number, uint32_t size) {
     return (last + number) & (size - 1);
   }
-
- // Returns _expected_ if one of entries given by the first _probe_ probes is
-  // equal to  _expected_. Otherwise, returns the entry given by the probe
-  // number _probe_.
-  uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected);
-
-  void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode);
-
-  // Rehashes this hash-table into the new table.
-  void Rehash(Derived* new_table, Key key);

   // Attempt to shrink hash table after removal of key.
   static Handle<Derived> Shrink(Handle<Derived> table, Key key);

   // Ensure enough space for n additional elements.
-  MUST_USE_RESULT MaybeObject* EnsureCapacity(
-      int n,
-      Key key,
-      PretenureFlag pretenure = NOT_TENURED);
-  static Handle<Derived> EnsureCapacity(
+  MUST_USE_RESULT static Handle<Derived> EnsureCapacity(
       Handle<Derived> table,
       int n,
       Key key,
       PretenureFlag pretenure = NOT_TENURED);
+
+ private:
+ // Returns _expected_ if one of entries given by the first _probe_ probes is
+  // equal to  _expected_. Otherwise, returns the entry given by the probe
+  // number _probe_.
+  uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected);
+
+  void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode);
+
+  // Rehashes this hash-table into the new table.
+  void Rehash(Handle<Derived> new_table, Key key);
 };


@@ -4108,6 +4105,15 @@
   static void GenerateNewEnumerationIndices(Handle<Derived> dictionary);
static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex;
   static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
+
+ private:
+ // This is to hide HashTable::New() which could clash with Dictionary::New().
+  // The latter one must be used for creating Dictionary and successors.
+  MUST_USE_RESULT static Handle<Derived> New(
+      Isolate* isolate,
+      int at_least_space_for,
+      MinimumCapacity capacity_option,
+      PretenureFlag pretenure);
 };


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to