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

Side by Side Diff: src/objects-inl.h

Issue 6342: Specialized string equality based on representation (Closed)
Patch Set: Created 12 years, 2 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
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 && HeapObject::cast(this)->map()->instance_type() < FIRST_NONSTRING_TYPE; 112 && HeapObject::cast(this)->map()->instance_type() < FIRST_NONSTRING_TYPE;
113 } 113 }
114 114
115 115
116 bool Object::IsSeqString() { 116 bool Object::IsSeqString() {
117 return IsString() 117 return IsString()
118 && (String::cast(this)->representation_tag() == kSeqStringTag); 118 && (String::cast(this)->representation_tag() == kSeqStringTag);
119 } 119 }
120 120
121 121
122 bool Object::IsAsciiString() { 122 bool Object::IsSeqAsciiString() {
123 return IsString() && (String::cast(this)->is_ascii()); 123 return IsSeqString()
124 && String::cast(this)->IsAsciiRepresentation();
124 } 125 }
125 126
126 127
127 bool Object::IsTwoByteString() { 128 bool Object::IsSeqTwoByteString() {
128 return IsString() && (!String::cast(this)->is_ascii()); 129 return IsSeqString()
130 && !String::cast(this)->IsAsciiRepresentation();
129 } 131 }
130 132
131 133
134 bool Object::IsAsciiStringRepresentation() {
135 return IsString() && (String::cast(this)->is_ascii_representation());
136 }
137
138
139 bool Object::IsTwoByteStringRepresentation() {
140 return IsString() && (!String::cast(this)->is_ascii_representation());
141 }
142
143
132 bool Object::IsConsString() { 144 bool Object::IsConsString() {
133 return IsString() 145 return IsString()
134 && (String::cast(this)->representation_tag() == kConsStringTag); 146 && (String::cast(this)->representation_tag() == kConsStringTag);
135 } 147 }
136 148
137 149
138 bool Object::IsSlicedString() { 150 bool Object::IsSlicedString() {
139 return IsString() 151 return IsString()
140 && (String::cast(this)->representation_tag() == kSlicedStringTag); 152 && (String::cast(this)->representation_tag() == kSlicedStringTag);
141 } 153 }
142 154
143 155
144 bool Object::IsExternalString() { 156 bool Object::IsExternalString() {
145 return IsString() 157 return IsString()
146 && (String::cast(this)->representation_tag() == kExternalStringTag); 158 && (String::cast(this)->representation_tag() == kExternalStringTag);
147 } 159 }
148 160
149 161
150 bool Object::IsExternalAsciiString() { 162 bool Object::IsExternalAsciiString() {
151 return IsExternalString() && (String::cast(this)->is_ascii()); 163 return IsExternalString() && (String::cast(this)->is_ascii_representation());
152 } 164 }
153 165
154 166
155 bool Object::IsExternalTwoByteString() { 167 bool Object::IsExternalTwoByteString() {
156 return IsExternalString() && (!String::cast(this)->is_ascii()); 168 return IsExternalString() && (!String::cast(this)->is_ascii_representation());
157 } 169 }
158 170
159 171
160 bool Object::IsShortString() { 172 bool Object::IsShortString() {
161 return IsString() && (String::cast(this)->size_tag() == kShortStringTag); 173 return IsString() && (String::cast(this)->size_tag() == kShortStringTag);
162 } 174 }
163 175
164 176
165 bool Object::IsMediumString() { 177 bool Object::IsMediumString() {
166 return IsString() && (String::cast(this)->size_tag() == kMediumStringTag); 178 return IsString() && (String::cast(this)->size_tag() == kMediumStringTag);
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 1131
1120 1132
1121 CAST_ACCESSOR(FixedArray) 1133 CAST_ACCESSOR(FixedArray)
1122 CAST_ACCESSOR(DescriptorArray) 1134 CAST_ACCESSOR(DescriptorArray)
1123 CAST_ACCESSOR(Dictionary) 1135 CAST_ACCESSOR(Dictionary)
1124 CAST_ACCESSOR(SymbolTable) 1136 CAST_ACCESSOR(SymbolTable)
1125 CAST_ACCESSOR(CompilationCacheTable) 1137 CAST_ACCESSOR(CompilationCacheTable)
1126 CAST_ACCESSOR(MapCache) 1138 CAST_ACCESSOR(MapCache)
1127 CAST_ACCESSOR(String) 1139 CAST_ACCESSOR(String)
1128 CAST_ACCESSOR(SeqString) 1140 CAST_ACCESSOR(SeqString)
1129 CAST_ACCESSOR(AsciiString) 1141 CAST_ACCESSOR(SeqAsciiString)
1130 CAST_ACCESSOR(TwoByteString) 1142 CAST_ACCESSOR(SeqTwoByteString)
1131 CAST_ACCESSOR(ConsString) 1143 CAST_ACCESSOR(ConsString)
1132 CAST_ACCESSOR(SlicedString) 1144 CAST_ACCESSOR(SlicedString)
1133 CAST_ACCESSOR(ExternalString) 1145 CAST_ACCESSOR(ExternalString)
1134 CAST_ACCESSOR(ExternalAsciiString) 1146 CAST_ACCESSOR(ExternalAsciiString)
1135 CAST_ACCESSOR(ExternalTwoByteString) 1147 CAST_ACCESSOR(ExternalTwoByteString)
1136 CAST_ACCESSOR(JSObject) 1148 CAST_ACCESSOR(JSObject)
1137 CAST_ACCESSOR(Smi) 1149 CAST_ACCESSOR(Smi)
1138 CAST_ACCESSOR(Failure) 1150 CAST_ACCESSOR(Failure)
1139 CAST_ACCESSOR(HeapObject) 1151 CAST_ACCESSOR(HeapObject)
1140 CAST_ACCESSOR(HeapNumber) 1152 CAST_ACCESSOR(HeapNumber)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 if (str_type != kSeqStringTag && str_type != kExternalStringTag) { 1239 if (str_type != kSeqStringTag && str_type != kExternalStringTag) {
1228 Flatten(); 1240 Flatten();
1229 } 1241 }
1230 } 1242 }
1231 1243
1232 1244
1233 uint16_t String::Get(int index) { 1245 uint16_t String::Get(int index) {
1234 ASSERT(index >= 0 && index < length()); 1246 ASSERT(index >= 0 && index < length());
1235 switch (representation_tag()) { 1247 switch (representation_tag()) {
1236 case kSeqStringTag: 1248 case kSeqStringTag:
1237 return is_ascii() 1249 return is_ascii_representation()
1238 ? AsciiString::cast(this)->AsciiStringGet(index) 1250 ? SeqAsciiString::cast(this)->AsciiStringGet(index)
1239 : TwoByteString::cast(this)->TwoByteStringGet(index); 1251 : SeqTwoByteString::cast(this)->TwoByteStringGet(index);
1240 case kConsStringTag: 1252 case kConsStringTag:
1241 return ConsString::cast(this)->ConsStringGet(index); 1253 return ConsString::cast(this)->ConsStringGet(index);
1242 case kSlicedStringTag: 1254 case kSlicedStringTag:
1243 return SlicedString::cast(this)->SlicedStringGet(index); 1255 return SlicedString::cast(this)->SlicedStringGet(index);
1244 case kExternalStringTag: 1256 case kExternalStringTag:
1245 return is_ascii() 1257 return is_ascii_representation()
1246 ? ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index) 1258 ? ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index)
1247 : ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); 1259 : ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index);
1248 default: 1260 default:
1249 break; 1261 break;
1250 } 1262 }
1251 1263
1252 UNREACHABLE(); 1264 UNREACHABLE();
1253 return 0; 1265 return 0;
1254 } 1266 }
1255 1267
1256 1268
1257 void String::Set(int index, uint16_t value) { 1269 void String::Set(int index, uint16_t value) {
1258 ASSERT(index >= 0 && index < length()); 1270 ASSERT(index >= 0 && index < length());
1259 ASSERT(IsSeqString()); 1271 ASSERT(IsSeqString());
1260 1272
1261 return is_ascii() 1273 return is_ascii_representation()
1262 ? AsciiString::cast(this)->AsciiStringSet(index, value) 1274 ? SeqAsciiString::cast(this)->AsciiStringSet(index, value)
1263 : TwoByteString::cast(this)->TwoByteStringSet(index, value); 1275 : SeqTwoByteString::cast(this)->TwoByteStringSet(index, value);
1264 } 1276 }
1265 1277
1266 1278
1267 bool String::IsAscii() { 1279 bool String::IsAsciiRepresentation() {
1268 return is_ascii(); 1280 return is_ascii_representation();
1269 } 1281 }
1270 1282
1271 1283
1272 bool String::StringIsConsString() { 1284 bool String::StringIsConsString() {
1273 return representation_tag() == kConsStringTag; 1285 return representation_tag() == kConsStringTag;
1274 } 1286 }
1275 1287
1276 1288
1277 bool String::StringIsSlicedString() { 1289 bool String::StringIsSlicedString() {
1278 return representation_tag() == kSlicedStringTag; 1290 return representation_tag() == kSlicedStringTag;
(...skipping 13 matching lines...) Expand all
1292 bool String::is_symbol() { 1304 bool String::is_symbol() {
1293 return is_symbol_map(map()); 1305 return is_symbol_map(map());
1294 } 1306 }
1295 1307
1296 1308
1297 bool String::is_symbol_map(Map* map) { 1309 bool String::is_symbol_map(Map* map) {
1298 return (map->instance_type() & kIsSymbolMask) != 0; 1310 return (map->instance_type() & kIsSymbolMask) != 0;
1299 } 1311 }
1300 1312
1301 1313
1302 bool String::is_ascii() { 1314 bool String::is_ascii_representation() {
1303 return is_ascii_map(map()); 1315 return is_ascii_representation_map(map());
1304 } 1316 }
1305 1317
1306 1318
1307 bool String::is_ascii_map(Map* map) { 1319 bool String::is_ascii_representation_map(Map* map) {
1308 return (map->instance_type() & kStringEncodingMask) != 0; 1320 return (map->instance_type() & kStringEncodingMask) != 0;
1309 } 1321 }
1310 1322
1311 1323
1312 StringRepresentationTag String::representation_tag() { 1324 StringRepresentationTag String::representation_tag() {
1313 return map_representation_tag(map()); 1325 return map_representation_tag(map());
1314 } 1326 }
1315 1327
1316 1328
1317 StringRepresentationTag String::map_representation_tag(Map* map) { 1329 StringRepresentationTag String::map_representation_tag(Map* map) {
(...skipping 11 matching lines...) Expand all
1329 String* slice = String::cast(SlicedString::cast(this)->buffer()); 1341 String* slice = String::cast(SlicedString::cast(this)->buffer());
1330 StringRepresentationTag tag = slice->representation_tag(); 1342 StringRepresentationTag tag = slice->representation_tag();
1331 return tag == kSeqStringTag || tag == kExternalStringTag; 1343 return tag == kSeqStringTag || tag == kExternalStringTag;
1332 } 1344 }
1333 default: 1345 default:
1334 return true; 1346 return true;
1335 } 1347 }
1336 } 1348 }
1337 1349
1338 1350
1339 uint16_t AsciiString::AsciiStringGet(int index) { 1351 uint16_t SeqAsciiString::AsciiStringGet(int index) {
1340 ASSERT(index >= 0 && index < length()); 1352 ASSERT(index >= 0 && index < length());
1341 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); 1353 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize);
1342 } 1354 }
1343 1355
1344 1356
1345 void AsciiString::AsciiStringSet(int index, uint16_t value) { 1357 void SeqAsciiString::AsciiStringSet(int index, uint16_t value) {
1346 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode); 1358 ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode);
1347 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, 1359 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize,
1348 static_cast<byte>(value)); 1360 static_cast<byte>(value));
1349 } 1361 }
1350 1362
1351 1363
1352 Address AsciiString::GetCharsAddress() { 1364 Address SeqAsciiString::GetCharsAddress() {
1353 return FIELD_ADDR(this, kHeaderSize); 1365 return FIELD_ADDR(this, kHeaderSize);
1354 } 1366 }
1355 1367
1356 1368
1357 Address TwoByteString::GetCharsAddress() { 1369 Address SeqTwoByteString::GetCharsAddress() {
1358 return FIELD_ADDR(this, kHeaderSize); 1370 return FIELD_ADDR(this, kHeaderSize);
1359 } 1371 }
1360 1372
1361 1373
1362 uint16_t TwoByteString::TwoByteStringGet(int index) { 1374 uint16_t SeqTwoByteString::TwoByteStringGet(int index) {
1363 ASSERT(index >= 0 && index < length()); 1375 ASSERT(index >= 0 && index < length());
1364 return READ_SHORT_FIELD(this, kHeaderSize + index * kShortSize); 1376 return READ_SHORT_FIELD(this, kHeaderSize + index * kShortSize);
1365 } 1377 }
1366 1378
1367 1379
1368 void TwoByteString::TwoByteStringSet(int index, uint16_t value) { 1380 void SeqTwoByteString::TwoByteStringSet(int index, uint16_t value) {
1369 ASSERT(index >= 0 && index < length()); 1381 ASSERT(index >= 0 && index < length());
1370 WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value); 1382 WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value);
1371 } 1383 }
1372 1384
1373 1385
1374 int TwoByteString::TwoByteStringSize(Map* map) { 1386 int SeqTwoByteString::TwoByteStringSize(Map* map) {
1375 uint32_t length = READ_INT_FIELD(this, kLengthOffset); 1387 uint32_t length = READ_INT_FIELD(this, kLengthOffset);
1376 1388
1377 // Use the map (and not 'this') to compute the size tag, since 1389 // Use the map (and not 'this') to compute the size tag, since
1378 // TwoByteStringSize is called during GC when maps are encoded. 1390 // TwoByteStringSize is called during GC when maps are encoded.
1379 switch (map_size_tag(map)) { 1391 switch (map_size_tag(map)) {
1380 case kShortStringTag: 1392 case kShortStringTag:
1381 length = length >> kShortLengthShift; 1393 length = length >> kShortLengthShift;
1382 break; 1394 break;
1383 case kMediumStringTag: 1395 case kMediumStringTag:
1384 length = length >> kMediumLengthShift; 1396 length = length >> kMediumLengthShift;
1385 break; 1397 break;
1386 case kLongStringTag: 1398 case kLongStringTag:
1387 length = length >> kLongLengthShift; 1399 length = length >> kLongLengthShift;
1388 break; 1400 break;
1389 default: 1401 default:
1390 break; 1402 break;
1391 } 1403 }
1392 return SizeFor(length); 1404 return SizeFor(length);
1393 } 1405 }
1394 1406
1395 1407
1396 int AsciiString::AsciiStringSize(Map* map) { 1408 int SeqAsciiString::AsciiStringSize(Map* map) {
1397 uint32_t length = READ_INT_FIELD(this, kLengthOffset); 1409 uint32_t length = READ_INT_FIELD(this, kLengthOffset);
1398 1410
1399 // Use the map (and not 'this') to compute the size tag, since 1411 // Use the map (and not 'this') to compute the size tag, since
1400 // AsciiStringSize is called during GC when maps are encoded. 1412 // AsciiStringSize is called during GC when maps are encoded.
1401 switch (map_size_tag(map)) { 1413 switch (map_size_tag(map)) {
1402 case kShortStringTag: 1414 case kShortStringTag:
1403 length = length >> kShortLengthShift; 1415 length = length >> kShortLengthShift;
1404 break; 1416 break;
1405 case kMediumStringTag: 1417 case kMediumStringTag:
1406 length = length >> kMediumLengthShift; 1418 length = length >> kMediumLengthShift;
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
2238 #undef WRITE_INT_FIELD 2250 #undef WRITE_INT_FIELD
2239 #undef READ_SHORT_FIELD 2251 #undef READ_SHORT_FIELD
2240 #undef WRITE_SHORT_FIELD 2252 #undef WRITE_SHORT_FIELD
2241 #undef READ_BYTE_FIELD 2253 #undef READ_BYTE_FIELD
2242 #undef WRITE_BYTE_FIELD 2254 #undef WRITE_BYTE_FIELD
2243 2255
2244 2256
2245 } } // namespace v8::internal 2257 } } // namespace v8::internal
2246 2258
2247 #endif // V8_OBJECTS_INL_H_ 2259 #endif // V8_OBJECTS_INL_H_
OLDNEW
« src/objects.h ('K') | « src/objects.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698