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

Side by Side Diff: vm/object_test.cc

Issue 9594028: Add a first class GrowableObjectArray type in the VM and use it internally in the VM at all spots w… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/object_store.cc ('k') | vm/parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/assembler.h" 6 #include "vm/assembler.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 1732
1733 other_array = Array::New(kArrayLen - 1); 1733 other_array = Array::New(kArrayLen - 1);
1734 other_array.SetAt(0, array); 1734 other_array.SetAt(0, array);
1735 other_array.SetAt(2, array); 1735 other_array.SetAt(2, array);
1736 EXPECT(!array.Equals(other_array)); 1736 EXPECT(!array.Equals(other_array));
1737 1737
1738 EXPECT_EQ(0, Array::Handle(Array::Empty()).Length()); 1738 EXPECT_EQ(0, Array::Handle(Array::Empty()).Length());
1739 } 1739 }
1740 1740
1741 1741
1742 TEST_CASE(GrowableObjectArray) {
1743 const int kArrayLen = 5;
1744 Smi& value = Smi::Handle();
1745 Smi& expected_value = Smi::Handle();
1746 GrowableObjectArray& array = GrowableObjectArray::Handle();
1747
1748 // Test basic growing functionality.
1749 array = GrowableObjectArray::New(kArrayLen);
1750 EXPECT_EQ(kArrayLen, array.Capacity());
1751 EXPECT_EQ(0, array.Length());
1752 for (intptr_t i = 0; i < 10; i++) {
1753 value = Smi::New(i);
1754 array.Add(value);
1755 }
1756 EXPECT_EQ(10, array.Length());
1757 for (intptr_t i = 0; i < 10; i++) {
1758 expected_value = Smi::New(i);
1759 value ^= array.At(i);
1760 EXPECT(value.Equals(expected_value));
1761 }
1762 for (intptr_t i = 0; i < 10; i++) {
1763 value = Smi::New(i * 10);
1764 array.SetAt(i, value);
1765 }
1766 EXPECT_EQ(10, array.Length());
1767 for (intptr_t i = 0; i < 10; i++) {
1768 expected_value = Smi::New(i * 10);
1769 value ^= array.At(i);
1770 EXPECT(value.Equals(expected_value));
1771 }
1772
1773 // Test the MakeArray functionality to make sure the resulting array
1774 // object is properly setup.
1775 // 1. Should produce an array of length 2 and a remainder array of length 0.
1776 Array& new_array = Array::Handle();
1777 Object& obj = Object::Handle();
1778 uword addr = 0;
1779 intptr_t used_size = 0;
1780
1781 array = GrowableObjectArray::New(kArrayLen);
1782 EXPECT_EQ(kArrayLen, array.Capacity());
1783 EXPECT_EQ(0, array.Length());
1784 for (intptr_t i = 0; i < 2; i++) {
1785 value = Smi::New(i);
1786 array.Add(value);
1787 }
1788 used_size = Array::InstanceSize(array.Length());
1789 new_array = Array::MakeArray(array);
1790 addr = RawObject::ToAddr(new_array.raw());
1791 obj = RawObject::FromAddr(addr);
1792 EXPECT(obj.IsArray());
1793 new_array ^= obj.raw();
1794 EXPECT_EQ(2, new_array.Length());
1795 addr += used_size;
1796 obj = RawObject::FromAddr(addr);
1797 EXPECT(obj.IsArray());
1798 new_array ^= obj.raw();
1799 EXPECT_EQ(0, new_array.Length());
1800
1801 // 2. Should produce an array of length 3 and a remainder object.
1802 array = GrowableObjectArray::New(kArrayLen);
1803 EXPECT_EQ(kArrayLen, array.Capacity());
1804 EXPECT_EQ(0, array.Length());
1805 for (intptr_t i = 0; i < 3; i++) {
1806 value = Smi::New(i);
1807 array.Add(value);
1808 }
1809 used_size = Array::InstanceSize(array.Length());
1810 new_array = Array::MakeArray(array);
1811 addr = RawObject::ToAddr(new_array.raw());
1812 obj = RawObject::FromAddr(addr);
1813 EXPECT(obj.IsArray());
1814 new_array ^= obj.raw();
1815 EXPECT_EQ(3, new_array.Length());
1816 addr += used_size;
1817 obj = RawObject::FromAddr(addr);
1818 EXPECT(!obj.IsArray());
1819
1820 // 3. Should produce an array of length 1 and a remainder array of length 2.
1821 array = GrowableObjectArray::New(kArrayLen + 3);
1822 EXPECT_EQ((kArrayLen + 3), array.Capacity());
1823 EXPECT_EQ(0, array.Length());
1824 for (intptr_t i = 0; i < 1; i++) {
1825 value = Smi::New(i);
1826 array.Add(value);
1827 }
1828 used_size = Array::InstanceSize(array.Length());
1829 new_array = Array::MakeArray(array);
1830 addr = RawObject::ToAddr(new_array.raw());
1831 obj = RawObject::FromAddr(addr);
1832 EXPECT(obj.IsArray());
1833 new_array ^= obj.raw();
1834 EXPECT_EQ(1, new_array.Length());
1835 addr += used_size;
1836 obj = RawObject::FromAddr(addr);
1837 EXPECT(obj.IsArray());
1838 new_array ^= obj.raw();
1839 EXPECT_EQ(2, new_array.Length());
1840 }
1841
1842
1742 TEST_CASE(ExternalByteArray) { 1843 TEST_CASE(ExternalByteArray) {
1743 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 }; 1844 uint8_t data[] = { 253, 254, 255, 0, 1, 2, 3, 4 };
1744 intptr_t data_length = ARRAY_SIZE(data); 1845 intptr_t data_length = ARRAY_SIZE(data);
1745 1846
1746 const ExternalByteArray& array1 = 1847 const ExternalByteArray& array1 =
1747 ExternalByteArray::Handle(ExternalByteArray::New(data, 1848 ExternalByteArray::Handle(ExternalByteArray::New(data,
1748 data_length, 1849 data_length,
1749 NULL, 1850 NULL,
1750 NULL)); 1851 NULL));
1751 EXPECT(!array1.IsNull()); 1852 EXPECT(!array1.IsNull());
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 EXPECT_EQ(2, test_classes.length()); 2785 EXPECT_EQ(2, test_classes.length());
2685 EXPECT_EQ(smi_class.raw(), test_classes[0]->raw()); 2786 EXPECT_EQ(smi_class.raw(), test_classes[0]->raw());
2686 EXPECT_EQ(smi_class.raw(), test_classes[1]->raw()); 2787 EXPECT_EQ(smi_class.raw(), test_classes[1]->raw());
2687 EXPECT_EQ(target1.raw(), test_target.raw()); 2788 EXPECT_EQ(target1.raw(), test_target.raw());
2688 } 2789 }
2689 2790
2690 2791
2691 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 2792 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
2692 2793
2693 } // namespace dart 2794 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object_store.cc ('k') | vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698