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

Side by Side Diff: src/heap.cc

Issue 385004: Remove sliced string string type... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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
« no previous file with comments | « src/heap.h ('k') | src/ia32/codegen-ia32.cc » ('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 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1745 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 share->set_inferred_name(empty_string()); 1756 share->set_inferred_name(empty_string());
1757 share->set_compiler_hints(0); 1757 share->set_compiler_hints(0);
1758 share->set_this_property_assignments_count(0); 1758 share->set_this_property_assignments_count(0);
1759 share->set_this_property_assignments(undefined_value()); 1759 share->set_this_property_assignments(undefined_value());
1760 return result; 1760 return result;
1761 } 1761 }
1762 1762
1763 1763
1764 Object* Heap::AllocateConsString(String* first, String* second) { 1764 Object* Heap::AllocateConsString(String* first, String* second) {
1765 int first_length = first->length(); 1765 int first_length = first->length();
1766 if (first_length == 0) return second; 1766 if (first_length == 0) {
1767 return second;
1768 }
1767 1769
1768 int second_length = second->length(); 1770 int second_length = second->length();
1769 if (second_length == 0) return first; 1771 if (second_length == 0) {
1772 return first;
1773 }
1770 1774
1771 int length = first_length + second_length; 1775 int length = first_length + second_length;
1772 bool is_ascii = first->IsAsciiRepresentation() 1776 bool is_ascii = first->IsAsciiRepresentation()
1773 && second->IsAsciiRepresentation(); 1777 && second->IsAsciiRepresentation();
1774 1778
1775 // Make sure that an out of memory exception is thrown if the length 1779 // Make sure that an out of memory exception is thrown if the length
1776 // of the new cons string is too large. 1780 // of the new cons string is too large.
1777 if (length > String::kMaxLength || length < 0) { 1781 if (length > String::kMaxLength || length < 0) {
1778 Top::context()->mark_out_of_memory(); 1782 Top::context()->mark_out_of_memory();
1779 return Failure::OutOfMemoryException(); 1783 return Failure::OutOfMemoryException();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 if (result->IsFailure()) return result; 1826 if (result->IsFailure()) return result;
1823 ASSERT(InNewSpace(result)); 1827 ASSERT(InNewSpace(result));
1824 ConsString* cons_string = ConsString::cast(result); 1828 ConsString* cons_string = ConsString::cast(result);
1825 cons_string->set_first(first, SKIP_WRITE_BARRIER); 1829 cons_string->set_first(first, SKIP_WRITE_BARRIER);
1826 cons_string->set_second(second, SKIP_WRITE_BARRIER); 1830 cons_string->set_second(second, SKIP_WRITE_BARRIER);
1827 cons_string->set_length(length); 1831 cons_string->set_length(length);
1828 return result; 1832 return result;
1829 } 1833 }
1830 1834
1831 1835
1832 Object* Heap::AllocateSlicedString(String* buffer,
1833 int start,
1834 int end) {
1835 int length = end - start;
1836
1837 // If the resulting string is small make a sub string.
1838 if (length <= String::kMinNonFlatLength) {
1839 return Heap::AllocateSubString(buffer, start, end);
1840 }
1841
1842 Map* map;
1843 if (length <= String::kMaxShortSize) {
1844 map = buffer->IsAsciiRepresentation() ?
1845 short_sliced_ascii_string_map() :
1846 short_sliced_string_map();
1847 } else if (length <= String::kMaxMediumSize) {
1848 map = buffer->IsAsciiRepresentation() ?
1849 medium_sliced_ascii_string_map() :
1850 medium_sliced_string_map();
1851 } else {
1852 map = buffer->IsAsciiRepresentation() ?
1853 long_sliced_ascii_string_map() :
1854 long_sliced_string_map();
1855 }
1856
1857 Object* result = Allocate(map, NEW_SPACE);
1858 if (result->IsFailure()) return result;
1859
1860 SlicedString* sliced_string = SlicedString::cast(result);
1861 sliced_string->set_buffer(buffer);
1862 sliced_string->set_start(start);
1863 sliced_string->set_length(length);
1864
1865 return result;
1866 }
1867
1868
1869 Object* Heap::AllocateSubString(String* buffer, 1836 Object* Heap::AllocateSubString(String* buffer,
1870 int start, 1837 int start,
1871 int end) { 1838 int end) {
1872 int length = end - start; 1839 int length = end - start;
1873 1840
1874 if (length == 1) { 1841 if (length == 1) {
1875 return Heap::LookupSingleCharacterStringFromCode( 1842 return Heap::LookupSingleCharacterStringFromCode(
1876 buffer->Get(start)); 1843 buffer->Get(start));
1877 } 1844 }
1878 1845
1879 // Make an attempt to flatten the buffer to reduce access time. 1846 // Make an attempt to flatten the buffer to reduce access time.
1880 if (!buffer->IsFlat()) { 1847 if (!buffer->IsFlat()) {
1881 buffer->TryFlatten(); 1848 buffer->TryFlatten();
1882 } 1849 }
1883 1850
1884 Object* result = buffer->IsAsciiRepresentation() 1851 Object* result = buffer->IsAsciiRepresentation()
1885 ? AllocateRawAsciiString(length) 1852 ? AllocateRawAsciiString(length)
1886 : AllocateRawTwoByteString(length); 1853 : AllocateRawTwoByteString(length);
1887 if (result->IsFailure()) return result; 1854 if (result->IsFailure()) return result;
1855 String* string_result = String::cast(result);
1888 1856
1889 // Copy the characters into the new object. 1857 // Copy the characters into the new object.
1890 String* string_result = String::cast(result); 1858 if (buffer->IsAsciiRepresentation()) {
1891 StringHasher hasher(length); 1859 ASSERT(string_result->IsAsciiRepresentation());
1892 int i = 0; 1860 char* dest = SeqAsciiString::cast(string_result)->GetChars();
1893 for (; i < length && hasher.is_array_index(); i++) { 1861 String::WriteToFlat(buffer, dest, start, end);
1894 uc32 c = buffer->Get(start + i); 1862 } else {
1895 hasher.AddCharacter(c); 1863 ASSERT(string_result->IsTwoByteRepresentation());
1896 string_result->Set(i, c); 1864 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars();
1865 String::WriteToFlat(buffer, dest, start, end);
1897 } 1866 }
1898 for (; i < length; i++) { 1867
1899 uc32 c = buffer->Get(start + i);
1900 hasher.AddCharacterNoIndex(c);
1901 string_result->Set(i, c);
1902 }
1903 string_result->set_length_field(hasher.GetHashField());
1904 return result; 1868 return result;
1905 } 1869 }
1906 1870
1907 1871
1908 Object* Heap::AllocateExternalStringFromAscii( 1872 Object* Heap::AllocateExternalStringFromAscii(
1909 ExternalAsciiString::Resource* resource) { 1873 ExternalAsciiString::Resource* resource) {
1910 Map* map; 1874 Map* map;
1911 int length = resource->length(); 1875 int length = resource->length();
1912 if (length <= String::kMaxShortSize) { 1876 if (length <= String::kMaxShortSize) {
1913 map = short_external_ascii_string_map(); 1877 map = short_external_ascii_string_map();
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2593 if (map == short_cons_ascii_string_map()) { 2557 if (map == short_cons_ascii_string_map()) {
2594 return short_cons_ascii_symbol_map(); 2558 return short_cons_ascii_symbol_map();
2595 } 2559 }
2596 if (map == medium_cons_ascii_string_map()) { 2560 if (map == medium_cons_ascii_string_map()) {
2597 return medium_cons_ascii_symbol_map(); 2561 return medium_cons_ascii_symbol_map();
2598 } 2562 }
2599 if (map == long_cons_ascii_string_map()) { 2563 if (map == long_cons_ascii_string_map()) {
2600 return long_cons_ascii_symbol_map(); 2564 return long_cons_ascii_symbol_map();
2601 } 2565 }
2602 2566
2603 if (map == short_sliced_string_map()) return short_sliced_symbol_map();
2604 if (map == medium_sliced_string_map()) return medium_sliced_symbol_map();
2605 if (map == long_sliced_string_map()) return long_sliced_symbol_map();
2606
2607 if (map == short_sliced_ascii_string_map()) {
2608 return short_sliced_ascii_symbol_map();
2609 }
2610 if (map == medium_sliced_ascii_string_map()) {
2611 return medium_sliced_ascii_symbol_map();
2612 }
2613 if (map == long_sliced_ascii_string_map()) {
2614 return long_sliced_ascii_symbol_map();
2615 }
2616
2617 if (map == short_external_string_map()) { 2567 if (map == short_external_string_map()) {
2618 return short_external_symbol_map(); 2568 return short_external_symbol_map();
2619 } 2569 }
2620 if (map == medium_external_string_map()) { 2570 if (map == medium_external_string_map()) {
2621 return medium_external_symbol_map(); 2571 return medium_external_symbol_map();
2622 } 2572 }
2623 if (map == long_external_string_map()) { 2573 if (map == long_external_string_map()) {
2624 return long_external_symbol_map(); 2574 return long_external_symbol_map();
2625 } 2575 }
2626 2576
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after
4035 for (int i = 0; i < kNumberOfCaches; i++) { 3985 for (int i = 0; i < kNumberOfCaches; i++) {
4036 if (caches_[i] != NULL) { 3986 if (caches_[i] != NULL) {
4037 delete caches_[i]; 3987 delete caches_[i];
4038 caches_[i] = NULL; 3988 caches_[i] = NULL;
4039 } 3989 }
4040 } 3990 }
4041 } 3991 }
4042 3992
4043 3993
4044 } } // namespace v8::internal 3994 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/ia32/codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698