Use handle lists in Map::FindTransitionedMap.
authorulan@chromium.org <ulan@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 24 Oct 2011 13:45:19 +0000 (13:45 +0000)
committerulan@chromium.org <ulan@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 24 Oct 2011 13:45:19 +0000 (13:45 +0000)
BUG=
TEST=

Review URL: http://codereview.chromium.org/8373030

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9757 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/hydrogen.cc
src/objects.cc

index 500e38f8daf8d851a9f2f4ef6eac4074a5807064..a50361c25846935695586b2030edf2574fc6901e 100644 (file)
@@ -4095,21 +4095,21 @@ HValue* HGraphBuilder::HandlePolymorphicElementAccess(HValue* object,
   }
 
   // Elements_kind transition support.
-  MapList transition_target(maps->length());
+  MapHandleList transition_target(maps->length());
   // Collect possible transition targets.
-  MapList possible_transitioned_maps(maps->length());
+  MapHandleList possible_transitioned_maps(maps->length());
   for (int i = 0; i < maps->length(); ++i) {
     Handle<Map> map = maps->at(i);
     ElementsKind elements_kind = map->elements_kind();
     if (elements_kind == FAST_DOUBLE_ELEMENTS ||
         elements_kind == FAST_ELEMENTS) {
-      possible_transitioned_maps.Add(*map);
+      possible_transitioned_maps.Add(map);
     }
   }
   // Get transition target for each map (NULL == no transition).
   for (int i = 0; i < maps->length(); ++i) {
     Handle<Map> map = maps->at(i);
-    Map* transitioned_map =
+    Handle<Map> transitioned_map =
         map->FindTransitionedMap(&possible_transitioned_maps);
     transition_target.Add(transitioned_map);
   }
@@ -4119,9 +4119,9 @@ HValue* HGraphBuilder::HandlePolymorphicElementAccess(HValue* object,
   for (int i = 0; i < maps->length(); ++i) {
     Handle<Map> map = maps->at(i);
     ASSERT(map->IsMap());
-    if (transition_target.at(i) != NULL) {
+    if (!transition_target.at(i).is_null()) {
       object = AddInstruction(new(zone()) HTransitionElementsKind(
-          object, map, Handle<Map>(transition_target.at(i))));
+          object, map, transition_target.at(i)));
     } else {
       type_todo[map->elements_kind()] = true;
       if (map->elements_kind() >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND) {
index b30793062158debb05fb64424e2bd2d9568ee17b..e1cae4641dcf2d2c8717dd2f00e44dadda1d96de 100644 (file)
@@ -2181,47 +2181,51 @@ void Map::LookupInDescriptors(JSObject* holder,
 }
 
 
-// If |map| is contained in |maps_list|, returns |map|; otherwise returns NULL.
-static bool ContainsMap(MapList* maps_list, Map* map) {
-  for (int i = 0; i < maps_list->length(); ++i) {
-    if (maps_list->at(i) == map) return true;
+static bool ContainsMap(MapHandleList* maps, Handle<Map> map) {
+  ASSERT(!map.is_null());
+  for (int i = 0; i < maps->length(); ++i) {
+    if (!maps->at(i).is_null() && maps->at(i).is_identical_to(map)) return true;
   }
   return false;
 }
 
 
-Handle<Map> Map::FindTransitionedMap(MapHandleList* candidates) {
-  MapList raw_candidates(candidates->length());
-  Map* result = FindTransitionedMap(UnwrapHandleList(&raw_candidates,
-                                                     candidates));
-  return (result == NULL) ? Handle<Map>::null() : Handle<Map>(result);
+template <class T>
+static Handle<T> MaybeNull(T* p) {
+  if (p == NULL) return Handle<T>::null();
+  return Handle<T>(p);
 }
 
 
-Map* Map::FindTransitionedMap(MapList* candidates) {
+Handle<Map> Map::FindTransitionedMap(MapHandleList* candidates) {
   ElementsKind elms_kind = elements_kind();
   if (elms_kind == FAST_DOUBLE_ELEMENTS) {
     bool dummy = true;
-    Map* fast_map = LookupElementsTransitionMap(FAST_ELEMENTS, &dummy);
-    if (fast_map == NULL) return NULL;
-    if (ContainsMap(candidates, fast_map)) return fast_map;
-    return NULL;
+    Handle<Map> fast_map =
+        MaybeNull(LookupElementsTransitionMap(FAST_ELEMENTS, &dummy));
+    if (!fast_map.is_null() && ContainsMap(candidates, fast_map)) {
+      return fast_map;
+    }
+    return Handle<Map>::null();
   }
   if (elms_kind == FAST_SMI_ONLY_ELEMENTS) {
     bool dummy = true;
-    Map* double_map = LookupElementsTransitionMap(FAST_DOUBLE_ELEMENTS, &dummy);
+    Handle<Map> double_map =
+        MaybeNull(LookupElementsTransitionMap(FAST_DOUBLE_ELEMENTS, &dummy));
     // In the current implementation, if the DOUBLE map doesn't exist, the
     // FAST map can't exist either.
-    if (double_map == NULL) return NULL;
-    Map* fast_map = double_map->LookupElementsTransitionMap(FAST_ELEMENTS,
-                                                            &dummy);
-    if (fast_map != NULL && ContainsMap(candidates, fast_map)) return fast_map;
+    if (double_map.is_null()) return Handle<Map>::null();
+    Handle<Map> fast_map =
+        MaybeNull(double_map->LookupElementsTransitionMap(FAST_ELEMENTS,
+                                                          &dummy));
+    if (!fast_map.is_null() && ContainsMap(candidates, fast_map)) {
+      return fast_map;
+    }
     if (ContainsMap(candidates, double_map)) return double_map;
   }
-  return NULL;
+  return Handle<Map>::null();
 }
 
-
 static Map* GetElementsTransitionMapFromDescriptor(Object* descriptor_contents,
                                                    ElementsKind elements_kind) {
   if (descriptor_contents->IsMap()) {