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

Unified Diff: src/objects.cc

Issue 256743002: Reland r20960: "HashTable::EnsureCapacity() handlified." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: The fix Created 6 years, 8 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/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 2a7252ca13825355cb715eb2bb5b543e16db838d..fcaa25aabdf10a8220944c733566d79dacd4c68e 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -14677,7 +14677,9 @@ int NameDictionary::FindEntry(Handle<Name> key) {
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 @@ void HashTable<Derived, Shape, Key>::Rehash(Key key) {
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);
-}
-
-
-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(
+ ((capacity > kMinCapacityForPretenure) &&
+ !isolate->heap()->InNewSpace(*table));
+ Handle<Derived> new_table = HashTable::New(
isolate,
- static_cast<HashTable*>(*table)->EnsureCapacity(n, key, pretenure),
- Derived);
+ nof * 2,
+ USE_DEFAULT_MINIMUM_CAPACITY,
+ should_pretenure ? TENURED : NOT_TENURED);
+
+ table->Rehash(new_table, key);
+ return new_table;
}
@@ -14846,13 +14834,13 @@ Handle<Derived> HashTable<Derived, Shape, Key>::Shrink(Handle<Derived> table,
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;
}
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698