Reviewers: danno, Dmitry Lomov (chromium), mvstanton,

Message:
As suggested by danno (see also https://codereview.chromium.org/18881004).

Description:
Use BuildGrowElementsCapacity for the TransitionElementsKind stub.

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/code-stubs-hydrogen.cc
  M src/hydrogen.h
  M src/hydrogen.cc


Index: src/code-stubs-hydrogen.cc
diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc
index 51734da2f16a754110d4acb04f6192e2aeb10664..fad8cfba2b9912a7600b4958d9955d2800ad482f 100644
--- a/src/code-stubs-hydrogen.cc
+++ b/src/code-stubs-hydrogen.cc
@@ -528,45 +528,32 @@ Handle<Code> KeyedStoreFastElementStub::GenerateCode() {

 template <>
 HValue* CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() {
-  Zone* zone = this->zone();
-
   HValue* js_array = GetParameter(0);
   HValue* map = GetParameter(1);

   info()->MarkAsSavesCallerDoubles();

-  AddInstruction(new(zone) HTrapAllocationMemento(js_array));
+  Add<HTrapAllocationMemento>(js_array);

   HInstruction* array_length =
       AddLoad(js_array, HObjectAccess::ForArrayLength());
   array_length->set_type(HType::Smi());

-  ElementsKind to_kind = casted_stub()->to_kind();
-  BuildNewSpaceArrayCheck(array_length, to_kind);
-
   IfBuilder if_builder(this);

-  if_builder.If<HCompareNumericAndBranch>(array_length,
-                                          graph()->GetConstant0(),
-                                          Token::EQ);
+  if_builder.IfNot<HCompareNumericAndBranch>(array_length,
+                                             graph()->GetConstant0(),
+                                             Token::EQ);
   if_builder.Then();

-  // Nothing to do, just change the map.
-
-  if_builder.Else();
-
   HInstruction* elements = AddLoadElements(js_array);

   HInstruction* elements_length = AddLoadFixedArrayLength(elements);

-  HValue* new_elements = BuildAllocateElementsAndInitializeElementsHeader(
-      context(), to_kind, elements_length);
-
-  BuildCopyElements(context(), elements,
-                    casted_stub()->from_kind(), new_elements,
-                    to_kind, array_length, elements_length);
-
-  AddStore(js_array, HObjectAccess::ForElementsPointer(), new_elements);
+  BuildGrowElementsCapacity(js_array, elements,
+                            casted_stub()->from_kind(),
+                            casted_stub()->to_kind(),
+                            array_length, elements_length);

   if_builder.End();

Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 074ca17fe101efbf5ceb08f4dcfceb16cdaadf11..ea86d6f61b1cee9b9580861241bcf979e2389020 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -1159,7 +1159,7 @@ HValue* HGraphBuilder::BuildCheckForCapacityGrow(HValue* object,
       BuildNewElementsCapacity(context, current_capacity);

   HValue* new_elements = BuildGrowElementsCapacity(object, elements,
-                                                   kind, length,
+                                                   kind, kind, length,
                                                    new_capacity);

   environment()->Push(new_elements);
@@ -1203,7 +1203,7 @@ HValue* HGraphBuilder::BuildCopyElementsOnWrite(HValue* object,

   HValue* capacity = AddLoadFixedArrayLength(elements);

-  HValue* new_elements = BuildGrowElementsCapacity(object, elements,
+  HValue* new_elements = BuildGrowElementsCapacity(object, elements, kind,
                                                    kind, length, capacity);

   environment()->Push(new_elements);
@@ -1475,17 +1475,18 @@ void HGraphBuilder::BuildNewSpaceArrayCheck(HValue* length, ElementsKind kind) {
 HValue* HGraphBuilder::BuildGrowElementsCapacity(HValue* object,
                                                  HValue* elements,
                                                  ElementsKind kind,
+                                                 ElementsKind new_kind,
                                                  HValue* length,
                                                  HValue* new_capacity) {
   HValue* context = environment()->LookupContext();

-  BuildNewSpaceArrayCheck(new_capacity, kind);
+  BuildNewSpaceArrayCheck(new_capacity, new_kind);

   HValue* new_elements = BuildAllocateElementsAndInitializeElementsHeader(
-      context, kind, new_capacity);
+      context, new_kind, new_capacity);

   BuildCopyElements(context, elements, kind,
-                    new_elements, kind,
+                    new_elements, new_kind,
                     length, new_capacity);

   AddStore(object, HObjectAccess::ForElementsPointer(), new_elements);
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index 4194b6d460de38ef463f5fa40f77b8dcc4d687db..bdf601dbda2d546f92cbb091eed55cae8a2fec9a 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -1378,6 +1378,7 @@ class HGraphBuilder {
   HValue* BuildGrowElementsCapacity(HValue* object,
                                     HValue* elements,
                                     ElementsKind kind,
+                                    ElementsKind new_kind,
                                     HValue* length,
                                     HValue* new_capacity);



--
--
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/groups/opt_out.


Reply via email to