OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 | 198 |
199 bool Object::IsExternalTwoByteString() { | 199 bool Object::IsExternalTwoByteString() { |
200 if (!IsString()) return false; | 200 if (!IsString()) return false; |
201 return StringShape(String::cast(this)).IsExternal() && | 201 return StringShape(String::cast(this)).IsExternal() && |
202 String::cast(this)->IsTwoByteRepresentation(); | 202 String::cast(this)->IsTwoByteRepresentation(); |
203 } | 203 } |
204 | 204 |
205 | 205 |
206 bool Object::IsSlicedString() { | |
207 if (!IsString()) return false; | |
208 return StringShape(String::cast(this)).IsSliced(); | |
209 } | |
210 | |
211 | |
212 StringShape::StringShape(String* str) | 206 StringShape::StringShape(String* str) |
213 : type_(str->map()->instance_type()) { | 207 : type_(str->map()->instance_type()) { |
214 set_valid(); | 208 set_valid(); |
215 ASSERT((type_ & kIsNotStringMask) == kStringTag); | 209 ASSERT((type_ & kIsNotStringMask) == kStringTag); |
216 } | 210 } |
217 | 211 |
218 | 212 |
219 StringShape::StringShape(Map* map) | 213 StringShape::StringShape(Map* map) |
220 : type_(map->instance_type()) { | 214 : type_(map->instance_type()) { |
221 set_valid(); | 215 set_valid(); |
222 ASSERT((type_ & kIsNotStringMask) == kStringTag); | 216 ASSERT((type_ & kIsNotStringMask) == kStringTag); |
223 } | 217 } |
224 | 218 |
225 | 219 |
226 StringShape::StringShape(InstanceType t) | 220 StringShape::StringShape(InstanceType t) |
227 : type_(static_cast<uint32_t>(t)) { | 221 : type_(static_cast<uint32_t>(t)) { |
228 set_valid(); | 222 set_valid(); |
229 ASSERT((type_ & kIsNotStringMask) == kStringTag); | 223 ASSERT((type_ & kIsNotStringMask) == kStringTag); |
230 } | 224 } |
231 | 225 |
232 | 226 |
233 bool StringShape::IsSymbol() { | 227 bool StringShape::IsSymbol() { |
234 ASSERT(valid()); | 228 ASSERT(valid()); |
235 return (type_ & kIsSymbolMask) == kSymbolTag; | 229 return (type_ & kIsSymbolMask) == kSymbolTag; |
236 } | 230 } |
237 | 231 |
238 | 232 |
239 bool String::IsAsciiRepresentation() { | 233 bool String::IsAsciiRepresentation() { |
240 uint32_t type = map()->instance_type(); | 234 uint32_t type = map()->instance_type(); |
241 if ((type & kStringRepresentationMask) == kSlicedStringTag) { | |
242 return SlicedString::cast(this)->buffer()->IsAsciiRepresentation(); | |
243 } | |
244 if ((type & kStringRepresentationMask) == kConsStringTag && | 235 if ((type & kStringRepresentationMask) == kConsStringTag && |
245 ConsString::cast(this)->second()->length() == 0) { | 236 ConsString::cast(this)->second()->length() == 0) { |
246 return ConsString::cast(this)->first()->IsAsciiRepresentation(); | 237 return ConsString::cast(this)->first()->IsAsciiRepresentation(); |
247 } | 238 } |
248 return (type & kStringEncodingMask) == kAsciiStringTag; | 239 return (type & kStringEncodingMask) == kAsciiStringTag; |
249 } | 240 } |
250 | 241 |
251 | 242 |
252 bool String::IsTwoByteRepresentation() { | 243 bool String::IsTwoByteRepresentation() { |
253 uint32_t type = map()->instance_type(); | 244 uint32_t type = map()->instance_type(); |
254 if ((type & kStringRepresentationMask) == kSlicedStringTag) { | 245 if ((type & kStringRepresentationMask) == kConsStringTag && |
255 return SlicedString::cast(this)->buffer()->IsTwoByteRepresentation(); | |
256 } else if ((type & kStringRepresentationMask) == kConsStringTag && | |
257 ConsString::cast(this)->second()->length() == 0) { | 246 ConsString::cast(this)->second()->length() == 0) { |
258 return ConsString::cast(this)->first()->IsTwoByteRepresentation(); | 247 return ConsString::cast(this)->first()->IsTwoByteRepresentation(); |
259 } | 248 } |
260 return (type & kStringEncodingMask) == kTwoByteStringTag; | 249 return (type & kStringEncodingMask) == kTwoByteStringTag; |
261 } | 250 } |
262 | 251 |
263 | 252 |
264 bool StringShape::IsCons() { | 253 bool StringShape::IsCons() { |
265 return (type_ & kStringRepresentationMask) == kConsStringTag; | 254 return (type_ & kStringRepresentationMask) == kConsStringTag; |
266 } | 255 } |
267 | 256 |
268 | 257 |
269 bool StringShape::IsSliced() { | |
270 return (type_ & kStringRepresentationMask) == kSlicedStringTag; | |
271 } | |
272 | |
273 | |
274 bool StringShape::IsExternal() { | 258 bool StringShape::IsExternal() { |
275 return (type_ & kStringRepresentationMask) == kExternalStringTag; | 259 return (type_ & kStringRepresentationMask) == kExternalStringTag; |
276 } | 260 } |
277 | 261 |
278 | 262 |
279 bool StringShape::IsSequential() { | 263 bool StringShape::IsSequential() { |
280 return (type_ & kStringRepresentationMask) == kSeqStringTag; | 264 return (type_ & kStringRepresentationMask) == kSeqStringTag; |
281 } | 265 } |
282 | 266 |
283 | 267 |
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 CAST_ACCESSOR(FixedArray) | 1579 CAST_ACCESSOR(FixedArray) |
1596 CAST_ACCESSOR(DescriptorArray) | 1580 CAST_ACCESSOR(DescriptorArray) |
1597 CAST_ACCESSOR(SymbolTable) | 1581 CAST_ACCESSOR(SymbolTable) |
1598 CAST_ACCESSOR(CompilationCacheTable) | 1582 CAST_ACCESSOR(CompilationCacheTable) |
1599 CAST_ACCESSOR(MapCache) | 1583 CAST_ACCESSOR(MapCache) |
1600 CAST_ACCESSOR(String) | 1584 CAST_ACCESSOR(String) |
1601 CAST_ACCESSOR(SeqString) | 1585 CAST_ACCESSOR(SeqString) |
1602 CAST_ACCESSOR(SeqAsciiString) | 1586 CAST_ACCESSOR(SeqAsciiString) |
1603 CAST_ACCESSOR(SeqTwoByteString) | 1587 CAST_ACCESSOR(SeqTwoByteString) |
1604 CAST_ACCESSOR(ConsString) | 1588 CAST_ACCESSOR(ConsString) |
1605 CAST_ACCESSOR(SlicedString) | |
1606 CAST_ACCESSOR(ExternalString) | 1589 CAST_ACCESSOR(ExternalString) |
1607 CAST_ACCESSOR(ExternalAsciiString) | 1590 CAST_ACCESSOR(ExternalAsciiString) |
1608 CAST_ACCESSOR(ExternalTwoByteString) | 1591 CAST_ACCESSOR(ExternalTwoByteString) |
1609 CAST_ACCESSOR(JSObject) | 1592 CAST_ACCESSOR(JSObject) |
1610 CAST_ACCESSOR(Smi) | 1593 CAST_ACCESSOR(Smi) |
1611 CAST_ACCESSOR(Failure) | 1594 CAST_ACCESSOR(Failure) |
1612 CAST_ACCESSOR(HeapObject) | 1595 CAST_ACCESSOR(HeapObject) |
1613 CAST_ACCESSOR(HeapNumber) | 1596 CAST_ACCESSOR(HeapNumber) |
1614 CAST_ACCESSOR(Oddball) | 1597 CAST_ACCESSOR(Oddball) |
1615 CAST_ACCESSOR(JSGlobalPropertyCell) | 1598 CAST_ACCESSOR(JSGlobalPropertyCell) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 uint16_t String::Get(int index) { | 1689 uint16_t String::Get(int index) { |
1707 ASSERT(index >= 0 && index < length()); | 1690 ASSERT(index >= 0 && index < length()); |
1708 switch (StringShape(this).full_representation_tag()) { | 1691 switch (StringShape(this).full_representation_tag()) { |
1709 case kSeqStringTag | kAsciiStringTag: | 1692 case kSeqStringTag | kAsciiStringTag: |
1710 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); | 1693 return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); |
1711 case kSeqStringTag | kTwoByteStringTag: | 1694 case kSeqStringTag | kTwoByteStringTag: |
1712 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); | 1695 return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); |
1713 case kConsStringTag | kAsciiStringTag: | 1696 case kConsStringTag | kAsciiStringTag: |
1714 case kConsStringTag | kTwoByteStringTag: | 1697 case kConsStringTag | kTwoByteStringTag: |
1715 return ConsString::cast(this)->ConsStringGet(index); | 1698 return ConsString::cast(this)->ConsStringGet(index); |
1716 case kSlicedStringTag | kAsciiStringTag: | |
1717 case kSlicedStringTag | kTwoByteStringTag: | |
1718 return SlicedString::cast(this)->SlicedStringGet(index); | |
1719 case kExternalStringTag | kAsciiStringTag: | 1699 case kExternalStringTag | kAsciiStringTag: |
1720 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); | 1700 return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); |
1721 case kExternalStringTag | kTwoByteStringTag: | 1701 case kExternalStringTag | kTwoByteStringTag: |
1722 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); | 1702 return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); |
1723 default: | 1703 default: |
1724 break; | 1704 break; |
1725 } | 1705 } |
1726 | 1706 |
1727 UNREACHABLE(); | 1707 UNREACHABLE(); |
1728 return 0; | 1708 return 0; |
(...skipping 10 matching lines...) Expand all Loading... |
1739 } | 1719 } |
1740 | 1720 |
1741 | 1721 |
1742 bool String::IsFlat() { | 1722 bool String::IsFlat() { |
1743 switch (StringShape(this).representation_tag()) { | 1723 switch (StringShape(this).representation_tag()) { |
1744 case kConsStringTag: { | 1724 case kConsStringTag: { |
1745 String* second = ConsString::cast(this)->second(); | 1725 String* second = ConsString::cast(this)->second(); |
1746 // Only flattened strings have second part empty. | 1726 // Only flattened strings have second part empty. |
1747 return second->length() == 0; | 1727 return second->length() == 0; |
1748 } | 1728 } |
1749 case kSlicedStringTag: { | |
1750 StringRepresentationTag tag = | |
1751 StringShape(SlicedString::cast(this)->buffer()).representation_tag(); | |
1752 return tag == kSeqStringTag || tag == kExternalStringTag; | |
1753 } | |
1754 default: | 1729 default: |
1755 return true; | 1730 return true; |
1756 } | 1731 } |
1757 } | 1732 } |
1758 | 1733 |
1759 | 1734 |
1760 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { | 1735 uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { |
1761 ASSERT(index >= 0 && index < length()); | 1736 ASSERT(index >= 0 && index < length()); |
1762 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); | 1737 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
1763 } | 1738 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 return READ_FIELD(this, kSecondOffset); | 1832 return READ_FIELD(this, kSecondOffset); |
1858 } | 1833 } |
1859 | 1834 |
1860 | 1835 |
1861 void ConsString::set_second(String* value, WriteBarrierMode mode) { | 1836 void ConsString::set_second(String* value, WriteBarrierMode mode) { |
1862 WRITE_FIELD(this, kSecondOffset, value); | 1837 WRITE_FIELD(this, kSecondOffset, value); |
1863 CONDITIONAL_WRITE_BARRIER(this, kSecondOffset, mode); | 1838 CONDITIONAL_WRITE_BARRIER(this, kSecondOffset, mode); |
1864 } | 1839 } |
1865 | 1840 |
1866 | 1841 |
1867 String* SlicedString::buffer() { | |
1868 return String::cast(READ_FIELD(this, kBufferOffset)); | |
1869 } | |
1870 | |
1871 | |
1872 void SlicedString::set_buffer(String* buffer) { | |
1873 WRITE_FIELD(this, kBufferOffset, buffer); | |
1874 WRITE_BARRIER(this, kBufferOffset); | |
1875 } | |
1876 | |
1877 | |
1878 int SlicedString::start() { | |
1879 return READ_INT_FIELD(this, kStartOffset); | |
1880 } | |
1881 | |
1882 | |
1883 void SlicedString::set_start(int start) { | |
1884 WRITE_INT_FIELD(this, kStartOffset, start); | |
1885 } | |
1886 | |
1887 | |
1888 ExternalAsciiString::Resource* ExternalAsciiString::resource() { | 1842 ExternalAsciiString::Resource* ExternalAsciiString::resource() { |
1889 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); | 1843 return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
1890 } | 1844 } |
1891 | 1845 |
1892 | 1846 |
1893 void ExternalAsciiString::set_resource( | 1847 void ExternalAsciiString::set_resource( |
1894 ExternalAsciiString::Resource* resource) { | 1848 ExternalAsciiString::Resource* resource) { |
1895 *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)) = resource; | 1849 *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)) = resource; |
1896 } | 1850 } |
1897 | 1851 |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3148 #undef WRITE_INT_FIELD | 3102 #undef WRITE_INT_FIELD |
3149 #undef READ_SHORT_FIELD | 3103 #undef READ_SHORT_FIELD |
3150 #undef WRITE_SHORT_FIELD | 3104 #undef WRITE_SHORT_FIELD |
3151 #undef READ_BYTE_FIELD | 3105 #undef READ_BYTE_FIELD |
3152 #undef WRITE_BYTE_FIELD | 3106 #undef WRITE_BYTE_FIELD |
3153 | 3107 |
3154 | 3108 |
3155 } } // namespace v8::internal | 3109 } } // namespace v8::internal |
3156 | 3110 |
3157 #endif // V8_OBJECTS_INL_H_ | 3111 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |