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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 137 |
138 bool Object::IsSeqString() { | 138 bool Object::IsSeqString() { |
139 if (!IsString()) return false; | 139 if (!IsString()) return false; |
140 return StringShape(String::cast(this)).IsSequential(); | 140 return StringShape(String::cast(this)).IsSequential(); |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 bool Object::IsSeqAsciiString() { | 144 bool Object::IsSeqAsciiString() { |
145 if (!IsString()) return false; | 145 if (!IsString()) return false; |
146 return StringShape(String::cast(this)).IsSequential() && | 146 return StringShape(String::cast(this)).IsSequential() && |
147 StringShape(String::cast(this)).IsAsciiRepresentation(); | 147 String::cast(this)->IsAsciiRepresentation(); |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 bool Object::IsSeqTwoByteString() { | 151 bool Object::IsSeqTwoByteString() { |
152 if (!IsString()) return false; | 152 if (!IsString()) return false; |
153 return StringShape(String::cast(this)).IsSequential() && | 153 return StringShape(String::cast(this)).IsSequential() && |
154 StringShape(String::cast(this)).IsTwoByteRepresentation(); | 154 String::cast(this)->IsTwoByteRepresentation(); |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 bool Object::IsExternalString() { | 158 bool Object::IsExternalString() { |
159 if (!IsString()) return false; | 159 if (!IsString()) return false; |
160 return StringShape(String::cast(this)).IsExternal(); | 160 return StringShape(String::cast(this)).IsExternal(); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 bool Object::IsExternalAsciiString() { | 164 bool Object::IsExternalAsciiString() { |
165 if (!IsString()) return false; | 165 if (!IsString()) return false; |
166 return StringShape(String::cast(this)).IsExternal() && | 166 return StringShape(String::cast(this)).IsExternal() && |
167 StringShape(String::cast(this)).IsAsciiRepresentation(); | 167 String::cast(this)->IsAsciiRepresentation(); |
168 } | 168 } |
169 | 169 |
170 | 170 |
171 bool Object::IsExternalTwoByteString() { | 171 bool Object::IsExternalTwoByteString() { |
172 if (!IsString()) return false; | 172 if (!IsString()) return false; |
173 return StringShape(String::cast(this)).IsExternal() && | 173 return StringShape(String::cast(this)).IsExternal() && |
174 StringShape(String::cast(this)).IsTwoByteRepresentation(); | 174 String::cast(this)->IsTwoByteRepresentation(); |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 bool Object::IsSlicedString() { | 178 bool Object::IsSlicedString() { |
179 if (!IsString()) return false; | 179 if (!IsString()) return false; |
180 return StringShape(String::cast(this)).IsSliced(); | 180 return StringShape(String::cast(this)).IsSliced(); |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 #endif // DEBUG | 184 #endif // DEBUG |
(...skipping 19 matching lines...) Expand all Loading... | |
204 ASSERT((type_ & kIsNotStringMask) == kStringTag); | 204 ASSERT((type_ & kIsNotStringMask) == kStringTag); |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 bool StringShape::IsSymbol() { | 208 bool StringShape::IsSymbol() { |
209 ASSERT(valid()); | 209 ASSERT(valid()); |
210 return (type_ & kIsSymbolMask) == kSymbolTag; | 210 return (type_ & kIsSymbolMask) == kSymbolTag; |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 bool StringShape::IsAsciiRepresentation() { | 214 bool String::IsAsciiRepresentation() { |
215 return (type_ & kStringEncodingMask) == kAsciiStringTag; | 215 uint32_t type = map()->instance_type(); |
216 if ((type & kStringRepresentationMask) == kSlicedStringTag) { | |
217 return SlicedString::cast(this)->buffer()->IsAsciiRepresentation(); | |
218 } else if ((type & kStringRepresentationMask) == kConsStringTag && | |
Lasse Reichstein
2009/05/01 09:47:01
You can omit the "else" here, since the former con
| |
219 ConsString::cast(this)->second()->length() == 0) { | |
220 return ConsString::cast(this)->first()->IsAsciiRepresentation(); | |
221 } | |
222 return (type & kStringEncodingMask) == kAsciiStringTag; | |
216 } | 223 } |
217 | 224 |
218 | 225 |
219 bool StringShape::IsTwoByteRepresentation() { | 226 bool String::IsTwoByteRepresentation() { |
220 return (type_ & kStringEncodingMask) == kTwoByteStringTag; | 227 uint32_t type = map()->instance_type(); |
228 if ((type & kStringRepresentationMask) == kSlicedStringTag) { | |
229 return SlicedString::cast(this)->buffer()->IsTwoByteRepresentation(); | |
230 } else if ((type & kStringRepresentationMask) == kConsStringTag && | |
231 ConsString::cast(this)->second()->length() == 0) { | |
232 return ConsString::cast(this)->first()->IsTwoByteRepresentation(); | |
233 } | |
234 return (type & kStringEncodingMask) == kTwoByteStringTag; | |
221 } | 235 } |
222 | 236 |
223 | 237 |
224 bool StringShape::IsCons() { | 238 bool StringShape::IsCons() { |
225 return (type_ & kStringRepresentationMask) == kConsStringTag; | 239 return (type_ & kStringRepresentationMask) == kConsStringTag; |
226 } | 240 } |
227 | 241 |
228 | 242 |
229 bool StringShape::IsSliced() { | 243 bool StringShape::IsSliced() { |
230 return (type_ & kStringRepresentationMask) == kSlicedStringTag; | 244 return (type_ & kStringRepresentationMask) == kSlicedStringTag; |
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1469 | 1483 |
1470 UNREACHABLE(); | 1484 UNREACHABLE(); |
1471 return 0; | 1485 return 0; |
1472 } | 1486 } |
1473 | 1487 |
1474 | 1488 |
1475 void String::Set(int index, uint16_t value) { | 1489 void String::Set(int index, uint16_t value) { |
1476 ASSERT(index >= 0 && index < length()); | 1490 ASSERT(index >= 0 && index < length()); |
1477 ASSERT(StringShape(this).IsSequential()); | 1491 ASSERT(StringShape(this).IsSequential()); |
1478 | 1492 |
1479 return StringShape(this).IsAsciiRepresentation() | 1493 return this->IsAsciiRepresentation() |
1480 ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value) | 1494 ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value) |
1481 : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value); | 1495 : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value); |
1482 } | 1496 } |
1483 | 1497 |
1484 | 1498 |
1485 bool String::IsFlat() { | 1499 bool String::IsFlat() { |
1486 switch (StringShape(this).representation_tag()) { | 1500 switch (StringShape(this).representation_tag()) { |
1487 case kConsStringTag: { | 1501 case kConsStringTag: { |
1488 String* second = ConsString::cast(this)->second(); | 1502 String* second = ConsString::cast(this)->second(); |
1489 // Only flattened strings have second part empty. | 1503 // Only flattened strings have second part empty. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1569 | 1583 |
1570 // Use the map (and not 'this') to compute the size tag, since | 1584 // Use the map (and not 'this') to compute the size tag, since |
1571 // AsciiStringSize is called during GC when maps are encoded. | 1585 // AsciiStringSize is called during GC when maps are encoded. |
1572 length >>= StringShape(instance_type).size_tag() + kLongLengthShift; | 1586 length >>= StringShape(instance_type).size_tag() + kLongLengthShift; |
1573 | 1587 |
1574 return SizeFor(length); | 1588 return SizeFor(length); |
1575 } | 1589 } |
1576 | 1590 |
1577 | 1591 |
1578 String* ConsString::first() { | 1592 String* ConsString::first() { |
1579 ASSERT(String::cast(READ_FIELD(this, kSecondOffset))->length() != 0 || | |
1580 StringShape( | |
1581 String::cast( | |
1582 READ_FIELD(this, kFirstOffset))).IsAsciiRepresentation() | |
1583 == StringShape(this).IsAsciiRepresentation()); | |
1584 return String::cast(READ_FIELD(this, kFirstOffset)); | 1593 return String::cast(READ_FIELD(this, kFirstOffset)); |
1585 } | 1594 } |
1586 | 1595 |
1587 | 1596 |
1588 Object* ConsString::unchecked_first() { | 1597 Object* ConsString::unchecked_first() { |
1589 return READ_FIELD(this, kFirstOffset); | 1598 return READ_FIELD(this, kFirstOffset); |
1590 } | 1599 } |
1591 | 1600 |
1592 | 1601 |
1593 void ConsString::set_first(String* value, WriteBarrierMode mode) { | 1602 void ConsString::set_first(String* value, WriteBarrierMode mode) { |
(...skipping 12 matching lines...) Expand all Loading... | |
1606 } | 1615 } |
1607 | 1616 |
1608 | 1617 |
1609 void ConsString::set_second(String* value, WriteBarrierMode mode) { | 1618 void ConsString::set_second(String* value, WriteBarrierMode mode) { |
1610 WRITE_FIELD(this, kSecondOffset, value); | 1619 WRITE_FIELD(this, kSecondOffset, value); |
1611 CONDITIONAL_WRITE_BARRIER(this, kSecondOffset, mode); | 1620 CONDITIONAL_WRITE_BARRIER(this, kSecondOffset, mode); |
1612 } | 1621 } |
1613 | 1622 |
1614 | 1623 |
1615 String* SlicedString::buffer() { | 1624 String* SlicedString::buffer() { |
1616 ASSERT( | |
1617 StringShape( | |
1618 String::cast(READ_FIELD(this, kBufferOffset))).IsAsciiRepresentation() | |
1619 == StringShape(this).IsAsciiRepresentation()); | |
1620 return String::cast(READ_FIELD(this, kBufferOffset)); | 1625 return String::cast(READ_FIELD(this, kBufferOffset)); |
1621 } | 1626 } |
1622 | 1627 |
1623 | 1628 |
1624 void SlicedString::set_buffer(String* buffer) { | 1629 void SlicedString::set_buffer(String* buffer) { |
1625 WRITE_FIELD(this, kBufferOffset, buffer); | 1630 WRITE_FIELD(this, kBufferOffset, buffer); |
1626 WRITE_BARRIER(this, kBufferOffset); | 1631 WRITE_BARRIER(this, kBufferOffset); |
1627 } | 1632 } |
1628 | 1633 |
1629 | 1634 |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2600 #undef WRITE_INT_FIELD | 2605 #undef WRITE_INT_FIELD |
2601 #undef READ_SHORT_FIELD | 2606 #undef READ_SHORT_FIELD |
2602 #undef WRITE_SHORT_FIELD | 2607 #undef WRITE_SHORT_FIELD |
2603 #undef READ_BYTE_FIELD | 2608 #undef READ_BYTE_FIELD |
2604 #undef WRITE_BYTE_FIELD | 2609 #undef WRITE_BYTE_FIELD |
2605 | 2610 |
2606 | 2611 |
2607 } } // namespace v8::internal | 2612 } } // namespace v8::internal |
2608 | 2613 |
2609 #endif // V8_OBJECTS_INL_H_ | 2614 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |