Reviewers: mvstanton,

Description:
Adding GetMoreGeneralElementsKind in elements-kind.h

BUG=

Please review this at https://codereview.chromium.org/1307743011/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+23, -27 lines):
  M src/builtins.cc
  M src/elements-kind.h
  M src/ic/ic.cc
  M src/lookup.cc
  M src/objects.cc
  M src/runtime/runtime-array.cc
  M src/runtime/runtime-literals.cc


Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index f06487ddfc695acc3a44fa7ababc945feaae2616..a1445b732c3c41548aded2e8848eea6dee2cc91d 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -650,9 +650,7 @@ BUILTIN(ArrayConcat) {
       ElementsKind arg_kind = JSArray::cast(arg)->map()->elements_kind();
       has_double = has_double || IsFastDoubleElementsKind(arg_kind);
       is_holey = is_holey || IsFastHoleyElementsKind(arg_kind);
-      if (IsMoreGeneralElementsKindTransition(elements_kind, arg_kind)) {
-        elements_kind = arg_kind;
-      }
+      elements_kind = GetMoreGeneralElementsKind(elements_kind, arg_kind);
     }
     if (is_holey) elements_kind = GetHoleyElementsKind(elements_kind);
   }
Index: src/elements-kind.h
diff --git a/src/elements-kind.h b/src/elements-kind.h
index d8234097c4371a34518b1f0b9e4e92ea4769e1f6..1397bd7c19c59a8a4d5771260d3cb2da91ac2295 100644
--- a/src/elements-kind.h
+++ b/src/elements-kind.h
@@ -211,6 +211,15 @@ bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind,
                                          ElementsKind to_kind);


+inline ElementsKind GetMoreGeneralElementsKind(ElementsKind from_kind,
+                                               ElementsKind to_kind) {
+  if (IsMoreGeneralElementsKindTransition(from_kind, to_kind)) {
+    return to_kind;
+  }
+  return from_kind;
+}
+
+
 inline bool IsTransitionableFastElementsKind(ElementsKind from_kind) {
   return IsFastElementsKind(from_kind) &&
       from_kind != TERMINAL_FAST_ELEMENTS_KIND;
Index: src/ic/ic.cc
diff --git a/src/ic/ic.cc b/src/ic/ic.cc
index 85e3f3c889e0e0a617760eb3d3e1e49b05f2a8f4..3ea251cd7b52e9569ff156d9f83d8eae20056cff 100644
--- a/src/ic/ic.cc
+++ b/src/ic/ic.cc
@@ -275,11 +275,8 @@ bool IC::TryRemoveInvalidPrototypeDependentStub(Handle<Object> receiver,
     if (first_map == NULL) return false;
     Handle<Map> old_map(first_map);
     if (old_map->is_deprecated()) return true;
-    if (IsMoreGeneralElementsKindTransition(old_map->elements_kind(),
- receiver_map()->elements_kind())) {
-      return true;
-    }
-    return false;
+    return IsMoreGeneralElementsKindTransition(old_map->elements_kind(),
+ receiver_map()->elements_kind());
   }

   CacheHolderFlag flag;
Index: src/lookup.cc
diff --git a/src/lookup.cc b/src/lookup.cc
index 013d074d7714c017e7122ef432b04693f55fa2e7..e9dc3d3a931863bb7eac1059d814b27a9ed43d2d 100644
--- a/src/lookup.cc
+++ b/src/lookup.cc
@@ -134,7 +134,7 @@ void LookupIterator::PrepareForDataProperty(Handle<Object> value) {
     ElementsKind kind = holder_map_->elements_kind();
     ElementsKind to = value->OptimalElementsKind();
     if (IsHoleyElementsKind(kind)) to = GetHoleyElementsKind(to);
-    to = IsMoreGeneralElementsKindTransition(kind, to) ? to : kind;
+    to = GetMoreGeneralElementsKind(kind, to);
     JSObject::TransitionElementsKind(holder, to);
     holder_map_ = handle(holder->map(), isolate_);

Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index c0539c493fa432fc0d8dde8993c02a3ded2c5178..ea666bedb43eb5ec119bcd8b977911c6952c09ad 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -4190,9 +4190,8 @@ void JSObject::AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map) {
   ElementsKind obj_kind = object->map()->elements_kind();
   ElementsKind map_kind = map->elements_kind();
   if (map_kind != obj_kind) {
-    ElementsKind to_kind = map_kind;
-    if (IsMoreGeneralElementsKindTransition(map_kind, obj_kind) ||
-        IsDictionaryElementsKind(obj_kind)) {
+    ElementsKind to_kind = GetMoreGeneralElementsKind(map_kind, obj_kind);
+    if (IsDictionaryElementsKind(obj_kind)) {
       to_kind = obj_kind;
     }
     if (IsDictionaryElementsKind(to_kind)) {
@@ -12608,7 +12607,7 @@ MaybeHandle<Object> JSObject::AddDataElement(Handle<JSObject> object,
     to = GetHoleyElementsKind(to);
     kind = GetHoleyElementsKind(kind);
   }
-  to = IsMoreGeneralElementsKindTransition(kind, to) ? to : kind;
+  to = GetMoreGeneralElementsKind(kind, to);
   ElementsAccessor* accessor = ElementsAccessor::ForKind(to);
   accessor->Add(object, index, value, attributes, new_capacity);

Index: src/runtime/runtime-array.cc
diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc
index c93f4423669ce7b14332fc8c06d3b41237f216d8..49eb1ad7024d9b643bccf150a56664bee0cc56a4 100644
--- a/src/runtime/runtime-array.cc
+++ b/src/runtime/runtime-array.cc
@@ -730,21 +730,16 @@ RUNTIME_FUNCTION(Runtime_ArrayConcat) {
       Handle<JSArray> array(Handle<JSArray>::cast(obj));
       length_estimate = static_cast<uint32_t>(array->length()->Number());
       if (length_estimate != 0) {
-        ElementsKind array_kind =
-            GetPackedElementsKind(array->map()->elements_kind());
-        if (IsMoreGeneralElementsKindTransition(kind, array_kind)) {
-          kind = array_kind;
-        }
+        kind = GetMoreGeneralElementsKind(
+            kind, GetPackedElementsKind(array->map()->elements_kind()));
       }
       element_estimate = EstimateElementCount(array);
     } else {
       if (obj->IsHeapObject()) {
         if (obj->IsNumber()) {
- if (IsMoreGeneralElementsKindTransition(kind, FAST_DOUBLE_ELEMENTS)) {
-            kind = FAST_DOUBLE_ELEMENTS;
-          }
- } else if (IsMoreGeneralElementsKindTransition(kind, FAST_ELEMENTS)) {
-          kind = FAST_ELEMENTS;
+          kind = GetMoreGeneralElementsKind(kind, FAST_DOUBLE_ELEMENTS);
+        } else {
+          kind = GetMoreGeneralElementsKind(kind, FAST_ELEMENTS);
         }
       }
       length_estimate = 1;
Index: src/runtime/runtime-literals.cc
diff --git a/src/runtime/runtime-literals.cc b/src/runtime/runtime-literals.cc index 9b1b2b220be9addf00c012bed6ed1afb7a7cfa7e..113193835d9852765363f1fb529ea657c8bb39f8 100644
--- a/src/runtime/runtime-literals.cc
+++ b/src/runtime/runtime-literals.cc
@@ -424,10 +424,8 @@ RUNTIME_FUNCTION(Runtime_StoreArrayLiteralElement) {
                                            ? FAST_HOLEY_ELEMENTS
                                            : FAST_ELEMENTS;
       JSObject::TransitionElementsKind(object, transitioned_kind);
-      ElementsKind boilerplate_elements_kind =
-          boilerplate_object->GetElementsKind();
-      if (IsMoreGeneralElementsKindTransition(boilerplate_elements_kind,
-                                              transitioned_kind)) {
+      if (IsMoreGeneralElementsKindTransition(
+              boilerplate_object->GetElementsKind(), transitioned_kind)) {
JSObject::TransitionElementsKind(boilerplate_object, transitioned_kind);
       }
     }


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