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

Side by Side Diff: runtime/vm/raw_object_snapshot.cc

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
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 "vm/bigint_operations.h" 5 #include "vm/bigint_operations.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/snapshot.h" 8 #include "vm/snapshot.h"
9 #include "vm/symbols.h" 9 #include "vm/symbols.h"
10 #include "vm/visitor.h" 10 #include "vm/visitor.h"
(...skipping 1697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 } 1708 }
1709 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); 1709 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash);
1710 } else { 1710 } else {
1711 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags, kind); 1711 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags, kind);
1712 } 1712 }
1713 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); 1713 reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
1714 return str_obj.raw(); 1714 return str_obj.raw();
1715 } 1715 }
1716 1716
1717 1717
1718 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader,
1719 intptr_t object_id,
1720 intptr_t tags,
1721 Snapshot::Kind kind) {
1722 // Read the length so that we can determine instance size to allocate.
1723 ASSERT(reader != NULL);
1724 intptr_t len = reader->ReadSmiValue();
1725 intptr_t hash = reader->ReadSmiValue();
1726 FourByteString& str_obj = FourByteString::ZoneHandle(reader->isolate(),
1727 FourByteString::null());
1728
1729 if (kind == Snapshot::kFull) {
1730 RawFourByteString* obj = reader->NewFourByteString(len);
1731 str_obj = obj;
1732 str_obj.set_tags(tags);
1733 obj->ptr()->hash_ = Smi::New(hash);
1734 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL;
1735 for (intptr_t i = 0; i < len; i++) {
1736 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions.
1737 *raw_ptr = reader->Read<uint32_t>();
1738 raw_ptr += 1;
1739 }
1740 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash);
1741 } else {
1742 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags, kind);
1743 }
1744 reader->AddBackRef(object_id, &str_obj, kIsDeserialized);
1745 return str_obj.raw();
1746 }
1747
1748
1749 template<typename T> 1718 template<typename T>
1750 static void StringWriteTo(SnapshotWriter* writer, 1719 static void StringWriteTo(SnapshotWriter* writer,
1751 intptr_t object_id, 1720 intptr_t object_id,
1752 Snapshot::Kind kind, 1721 Snapshot::Kind kind,
1753 intptr_t class_id, 1722 intptr_t class_id,
1754 intptr_t tags, 1723 intptr_t tags,
1755 RawSmi* length, 1724 RawSmi* length,
1756 RawSmi* hash, 1725 RawSmi* hash,
1757 T* data) { 1726 T* data) {
1758 ASSERT(writer != NULL); 1727 ASSERT(writer != NULL);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 object_id, 1774 object_id,
1806 kind, 1775 kind,
1807 kTwoByteStringCid, 1776 kTwoByteStringCid,
1808 writer->GetObjectTags(this), 1777 writer->GetObjectTags(this),
1809 ptr()->length_, 1778 ptr()->length_,
1810 ptr()->hash_, 1779 ptr()->hash_,
1811 ptr()->data_); 1780 ptr()->data_);
1812 } 1781 }
1813 1782
1814 1783
1815 void RawFourByteString::WriteTo(SnapshotWriter* writer,
1816 intptr_t object_id,
1817 Snapshot::Kind kind) {
1818 StringWriteTo(writer,
1819 object_id,
1820 kind,
1821 kFourByteStringCid,
1822 writer->GetObjectTags(this),
1823 ptr()->length_,
1824 ptr()->hash_,
1825 ptr()->data_);
1826 }
1827
1828
1829 RawExternalOneByteString* ExternalOneByteString::ReadFrom( 1784 RawExternalOneByteString* ExternalOneByteString::ReadFrom(
1830 SnapshotReader* reader, 1785 SnapshotReader* reader,
1831 intptr_t object_id, 1786 intptr_t object_id,
1832 intptr_t tags, 1787 intptr_t tags,
1833 Snapshot::Kind kind) { 1788 Snapshot::Kind kind) {
1834 UNREACHABLE(); 1789 UNREACHABLE();
1835 return ExternalOneByteString::null(); 1790 return ExternalOneByteString::null();
1836 } 1791 }
1837 1792
1838 1793
1839 RawExternalTwoByteString* ExternalTwoByteString::ReadFrom( 1794 RawExternalTwoByteString* ExternalTwoByteString::ReadFrom(
1840 SnapshotReader* reader, 1795 SnapshotReader* reader,
1841 intptr_t object_id, 1796 intptr_t object_id,
1842 intptr_t tags, 1797 intptr_t tags,
1843 Snapshot::Kind kind) { 1798 Snapshot::Kind kind) {
1844 UNREACHABLE(); 1799 UNREACHABLE();
1845 return ExternalTwoByteString::null(); 1800 return ExternalTwoByteString::null();
1846 } 1801 }
1847 1802
1848 1803
1849 RawExternalFourByteString* ExternalFourByteString::ReadFrom(
1850 SnapshotReader* reader,
1851 intptr_t object_id,
1852 intptr_t tags,
1853 Snapshot::Kind kind) {
1854 UNREACHABLE();
1855 return ExternalFourByteString::null();
1856 }
1857
1858
1859 void RawExternalOneByteString::WriteTo(SnapshotWriter* writer, 1804 void RawExternalOneByteString::WriteTo(SnapshotWriter* writer,
1860 intptr_t object_id, 1805 intptr_t object_id,
1861 Snapshot::Kind kind) { 1806 Snapshot::Kind kind) {
1862 // Serialize as a non-external one byte string. 1807 // Serialize as a non-external one byte string.
1863 StringWriteTo(writer, 1808 StringWriteTo(writer,
1864 object_id, 1809 object_id,
1865 kind, 1810 kind,
1866 kOneByteStringCid, 1811 kOneByteStringCid,
1867 writer->GetObjectTags(this), 1812 writer->GetObjectTags(this),
1868 ptr()->length_, 1813 ptr()->length_,
(...skipping 10 matching lines...) Expand all
1879 object_id, 1824 object_id,
1880 kind, 1825 kind,
1881 kTwoByteStringCid, 1826 kTwoByteStringCid,
1882 writer->GetObjectTags(this), 1827 writer->GetObjectTags(this),
1883 ptr()->length_, 1828 ptr()->length_,
1884 ptr()->hash_, 1829 ptr()->hash_,
1885 ptr()->external_data_->data()); 1830 ptr()->external_data_->data());
1886 } 1831 }
1887 1832
1888 1833
1889 void RawExternalFourByteString::WriteTo(SnapshotWriter* writer,
1890 intptr_t object_id,
1891 Snapshot::Kind kind) {
1892 // Serialize as a non-external four byte string.
1893 StringWriteTo(writer,
1894 object_id,
1895 kind,
1896 kFourByteStringCid,
1897 writer->GetObjectTags(this),
1898 ptr()->length_,
1899 ptr()->hash_,
1900 ptr()->external_data_->data());
1901 }
1902
1903
1904 RawBool* Bool::ReadFrom(SnapshotReader* reader, 1834 RawBool* Bool::ReadFrom(SnapshotReader* reader,
1905 intptr_t object_id, 1835 intptr_t object_id,
1906 intptr_t tags, 1836 intptr_t tags,
1907 Snapshot::Kind kind) { 1837 Snapshot::Kind kind) {
1908 UNREACHABLE(); 1838 UNREACHABLE();
1909 return Bool::null(); 1839 return Bool::null();
1910 } 1840 }
1911 1841
1912 1842
1913 void RawBool::WriteTo(SnapshotWriter* writer, 1843 void RawBool::WriteTo(SnapshotWriter* writer,
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 // Write out the class and tags information. 2237 // Write out the class and tags information.
2308 writer->WriteIndexedObject(kWeakPropertyCid); 2238 writer->WriteIndexedObject(kWeakPropertyCid);
2309 writer->WriteIntptrValue(writer->GetObjectTags(this)); 2239 writer->WriteIntptrValue(writer->GetObjectTags(this));
2310 2240
2311 // Write out all the other fields. 2241 // Write out all the other fields.
2312 writer->Write<RawObject*>(ptr()->key_); 2242 writer->Write<RawObject*>(ptr()->key_);
2313 writer->Write<RawObject*>(ptr()->value_); 2243 writer->Write<RawObject*>(ptr()->value_);
2314 } 2244 }
2315 2245
2316 } // namespace dart 2246 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698