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

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

Issue 8187: Serendipitously arrange the tags so that String.length() becomes a branch-fre... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 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 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 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 bool String::Equals(String* other) { 1264 bool String::Equals(String* other) {
1265 if (other == this) return true; 1265 if (other == this) return true;
1266 if (IsSymbol() && other->IsSymbol()) return false; 1266 if (IsSymbol() && other->IsSymbol()) return false;
1267 return SlowEquals(other); 1267 return SlowEquals(other);
1268 } 1268 }
1269 1269
1270 1270
1271 int String::length() { 1271 int String::length() {
1272 uint32_t len = READ_INT_FIELD(this, kLengthOffset); 1272 uint32_t len = READ_INT_FIELD(this, kLengthOffset);
1273 1273
1274 switch (size_tag()) { 1274 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift);
1275 case kShortStringTag: 1275 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift);
1276 return len >> kShortLengthShift; 1276 ASSERT(kLongStringTag == 0);
1277 case kMediumStringTag: 1277
1278 return len >> kMediumLengthShift; 1278 return len >> (size_tag() + kLongLengthShift);
1279 case kLongStringTag:
1280 return len >> kLongLengthShift;
1281 default:
1282 break;
1283 }
1284 UNREACHABLE();
1285 return 0;
1286 } 1279 }
1287 1280
1288 1281
1289 void String::set_length(int value) { 1282 void String::set_length(int value) {
1290 switch (size_tag()) { 1283 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift);
1291 case kShortStringTag: 1284 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift);
1292 WRITE_INT_FIELD(this, kLengthOffset, value << kShortLengthShift); 1285 ASSERT(kLongStringTag == 0);
1293 break; 1286
1294 case kMediumStringTag: 1287 WRITE_INT_FIELD(this, kLengthOffset, value << (size_tag() + kLongLengthShift)) ;
1295 WRITE_INT_FIELD(this, kLengthOffset, value << kMediumLengthShift);
1296 break;
1297 case kLongStringTag:
1298 WRITE_INT_FIELD(this, kLengthOffset, value << kLongLengthShift);
1299 break;
1300 default:
1301 UNREACHABLE();
1302 break;
1303 }
1304 } 1288 }
1305 1289
1306 1290
1307 uint32_t String::length_field() { 1291 uint32_t String::length_field() {
1308 return READ_UINT32_FIELD(this, kLengthOffset); 1292 return READ_UINT32_FIELD(this, kLengthOffset);
1309 } 1293 }
1310 1294
1311 1295
1312 void String::set_length_field(uint32_t value) { 1296 void String::set_length_field(uint32_t value) {
1313 WRITE_UINT32_FIELD(this, kLengthOffset, value); 1297 WRITE_UINT32_FIELD(this, kLengthOffset, value);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 1461
1478 void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) { 1462 void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) {
1479 ASSERT(index >= 0 && index < length()); 1463 ASSERT(index >= 0 && index < length());
1480 WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value); 1464 WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value);
1481 } 1465 }
1482 1466
1483 1467
1484 int SeqTwoByteString::SeqTwoByteStringSize(Map* map) { 1468 int SeqTwoByteString::SeqTwoByteStringSize(Map* map) {
1485 uint32_t length = READ_INT_FIELD(this, kLengthOffset); 1469 uint32_t length = READ_INT_FIELD(this, kLengthOffset);
1486 1470
1471 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift);
1472 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift);
1473 ASSERT(kLongStringTag == 0);
1474
1487 // Use the map (and not 'this') to compute the size tag, since 1475 // Use the map (and not 'this') to compute the size tag, since
1488 // TwoByteStringSize is called during GC when maps are encoded. 1476 // TwoByteStringSize is called during GC when maps are encoded.
1489 switch (map_size_tag(map)) { 1477 length >>= map_size_tag(map) + kLongLengthShift;
1490 case kShortStringTag: 1478
1491 length = length >> kShortLengthShift;
1492 break;
1493 case kMediumStringTag:
1494 length = length >> kMediumLengthShift;
1495 break;
1496 case kLongStringTag:
1497 length = length >> kLongLengthShift;
1498 break;
1499 default:
1500 break;
1501 }
1502 return SizeFor(length); 1479 return SizeFor(length);
1503 } 1480 }
1504 1481
1505 1482
1506 int SeqAsciiString::SeqAsciiStringSize(Map* map) { 1483 int SeqAsciiString::SeqAsciiStringSize(Map* map) {
1507 uint32_t length = READ_INT_FIELD(this, kLengthOffset); 1484 uint32_t length = READ_INT_FIELD(this, kLengthOffset);
1508 1485
1486 ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift);
1487 ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift);
1488 ASSERT(kLongStringTag == 0);
1489
1509 // Use the map (and not 'this') to compute the size tag, since 1490 // Use the map (and not 'this') to compute the size tag, since
1510 // AsciiStringSize is called during GC when maps are encoded. 1491 // AsciiStringSize is called during GC when maps are encoded.
1511 switch (map_size_tag(map)) { 1492 length >>= map_size_tag(map) + kLongLengthShift;
1512 case kShortStringTag:
1513 length = length >> kShortLengthShift;
1514 break;
1515 case kMediumStringTag:
1516 length = length >> kMediumLengthShift;
1517 break;
1518 case kLongStringTag:
1519 length = length >> kLongLengthShift;
1520 break;
1521 default:
1522 break;
1523 }
1524 1493
1525 return SizeFor(length); 1494 return SizeFor(length);
1526 } 1495 }
1527 1496
1528 1497
1529 Object* ConsString::first() { 1498 Object* ConsString::first() {
1530 return READ_FIELD(this, kFirstOffset); 1499 return READ_FIELD(this, kFirstOffset);
1531 } 1500 }
1532 1501
1533 1502
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 #undef WRITE_INT_FIELD 2353 #undef WRITE_INT_FIELD
2385 #undef READ_SHORT_FIELD 2354 #undef READ_SHORT_FIELD
2386 #undef WRITE_SHORT_FIELD 2355 #undef WRITE_SHORT_FIELD
2387 #undef READ_BYTE_FIELD 2356 #undef READ_BYTE_FIELD
2388 #undef WRITE_BYTE_FIELD 2357 #undef WRITE_BYTE_FIELD
2389 2358
2390 2359
2391 } } // namespace v8::internal 2360 } } // namespace v8::internal
2392 2361
2393 #endif // V8_OBJECTS_INL_H_ 2362 #endif // V8_OBJECTS_INL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698