Revision: 21246
Author:   [email protected]
Date:     Fri May  9 18:31:08 2014 UTC
Log:      Clean up hash creation code to use Handle<Smi> where possible

Also remove apparently-bogus TODO and reorder arguments in
Object::GetOrCreateHash to put Isolate first (as seems to
be the custom).

[email protected]

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

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/objects-inl.h
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h

=======================================
--- /branches/bleeding_edge/src/api.cc  Fri May  9 09:24:32 2014 UTC
+++ /branches/bleeding_edge/src/api.cc  Fri May  9 18:31:08 2014 UTC
@@ -3584,8 +3584,7 @@
   ENTER_V8(isolate);
   i::HandleScope scope(isolate);
   i::Handle<i::JSObject> self = Utils::OpenHandle(this);
-  return i::Handle<i::Smi>::cast(
-      i::JSReceiver::GetOrCreateIdentityHash(self))->value();
+  return i::JSReceiver::GetOrCreateIdentityHash(self)->value();
 }


=======================================
--- /branches/bleeding_edge/src/objects-inl.h   Fri May  9 16:18:58 2014 UTC
+++ /branches/bleeding_edge/src/objects-inl.h   Fri May  9 18:31:08 2014 UTC
@@ -6319,7 +6319,7 @@
 }


-Handle<Object> JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver> object) { +Handle<Smi> JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver> object) {
   return object->IsJSProxy()
       ? JSProxy::GetOrCreateIdentityHash(Handle<JSProxy>::cast(object))
       : JSObject::GetOrCreateIdentityHash(Handle<JSObject>::cast(object));
=======================================
--- /branches/bleeding_edge/src/objects.cc      Fri May  9 17:59:15 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Fri May  9 18:31:08 2014 UTC
@@ -945,11 +945,9 @@
 }


-Handle<Object> Object::GetOrCreateHash(Handle<Object> object,
-                                       Isolate* isolate) {
+Handle<Smi> Object::GetOrCreateHash(Isolate* isolate, Handle<Object> object) {
   Handle<Object> hash(object->GetHash(), isolate);
-  if (hash->IsSmi())
-    return hash;
+  if (hash->IsSmi()) return Handle<Smi>::cast(hash);

   ASSERT(object->IsJSReceiver());
return JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver>::cast(object));
@@ -5098,13 +5096,13 @@


 template<typename ProxyType>
-static Handle<Object> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) {
+static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) {
   Isolate* isolate = proxy->GetIsolate();

-  Handle<Object> hash(proxy->hash(), isolate);
-  if (hash->IsSmi()) return hash;
+  Handle<Object> maybe_hash(proxy->hash(), isolate);
+  if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash);

-  hash = handle(GenerateIdentityHash(isolate), isolate);
+  Handle<Smi> hash(GenerateIdentityHash(isolate), isolate);
   proxy->set_hash(*hash);
   return hash;
 }
@@ -5124,17 +5122,17 @@
 }


-Handle<Object> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
+Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
   if (object->IsJSGlobalProxy()) {
return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object));
   }

   Isolate* isolate = object->GetIsolate();

-  Handle<Object> hash(object->GetIdentityHash(), isolate);
-  if (hash->IsSmi()) return hash;
+  Handle<Object> maybe_hash(object->GetIdentityHash(), isolate);
+  if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash);

-  hash = handle(GenerateIdentityHash(isolate), isolate);
+  Handle<Smi> hash(GenerateIdentityHash(isolate), isolate);
SetHiddenProperty(object, isolate->factory()->identity_hash_string(), hash);
   return hash;
 }
@@ -5145,7 +5143,7 @@
 }


-Handle<Object> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) {
+Handle<Smi> JSProxy::GetOrCreateIdentityHash(Handle<JSProxy> proxy) {
   return GetOrCreateIdentityHashHelper(proxy);
 }

@@ -16114,7 +16112,7 @@
   Isolate* isolate = table->GetIsolate();

   // Make sure the key object has an identity hash code.
-  Handle<Object> hash = Object::GetOrCreateHash(key, isolate);
+  Handle<Smi> hash = Object::GetOrCreateHash(isolate, key);

   int entry = table->FindEntry(key);

@@ -16133,7 +16131,7 @@

   // Check whether the hash table should be extended.
   table = EnsureCapacity(table, 1, key);
- table->AddEntry(table->FindInsertionEntry(Handle<Smi>::cast(hash)->value()),
+  table->AddEntry(table->FindInsertionEntry(hash->value()),
                   *key,
                   *value);
   return table;
@@ -16426,8 +16424,8 @@

   table = EnsureGrowable(table);

-  Handle<Object> hash = GetOrCreateHash(key, table->GetIsolate());
-  int index = table->AddEntry(Smi::cast(*hash)->value());
+  Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key);
+  int index = table->AddEntry(hash->value());
   table->set(index, *key);
   return table;
 }
@@ -16468,8 +16466,8 @@

   table = EnsureGrowable(table);

-  Handle<Object> hash = GetOrCreateHash(key, table->GetIsolate());
-  int index = table->AddEntry(Smi::cast(*hash)->value());
+  Handle<Smi> hash = GetOrCreateHash(table->GetIsolate(), key);
+  int index = table->AddEntry(hash->value());
   table->set(index, *key);
   table->set(index + kValueOffset, *value);
   return table;
=======================================
--- /branches/bleeding_edge/src/objects.h       Fri May  9 17:59:15 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Fri May  9 18:31:08 2014 UTC
@@ -1503,10 +1503,7 @@
// Returns the permanent hash code associated with this object depending on // the actual object type. May create and store a hash code if needed and none
   // exists.
-  // TODO(rafaelw): Remove isolate parameter when objects.cc is fully
-  // handlified.
-  static Handle<Object> GetOrCreateHash(Handle<Object> object,
-                                        Isolate* isolate);
+ static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object> object);

   // Checks whether this object has the same value as the given one.  This
   // function is implemented according to ES5, section 9.12 and can be used
@@ -1972,7 +1969,7 @@

// Retrieves a permanent object identity hash code. May create and store a
   // hash code if needed and none exists.
-  inline static Handle<Object> GetOrCreateIdentityHash(
+  inline static Handle<Smi> GetOrCreateIdentityHash(
       Handle<JSReceiver> object);

   // Lookup a property.  If found, the result is valid and has
@@ -2884,7 +2881,7 @@

   MUST_USE_RESULT Object* GetIdentityHash();

-  static Handle<Object> GetOrCreateIdentityHash(Handle<JSObject> object);
+  static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);

   DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
 };
@@ -9874,7 +9871,7 @@

   MUST_USE_RESULT Object* GetIdentityHash();

-  static Handle<Object> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
+  static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);

   DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
 };

--
--
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