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

Side by Side Diff: src/heap.cc

Issue 100249: When strings can change from an ASCII representation to a... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ia32/regexp-macro-assembler-ia32.cc » ('j') | src/objects-inl.h » ('J')
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 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 share->set_inferred_name(empty_string()); 1416 share->set_inferred_name(empty_string());
1417 return result; 1417 return result;
1418 } 1418 }
1419 1419
1420 1420
1421 Object* Heap::AllocateConsString(String* first, 1421 Object* Heap::AllocateConsString(String* first,
1422 String* second) { 1422 String* second) {
1423 int first_length = first->length(); 1423 int first_length = first->length();
1424 int second_length = second->length(); 1424 int second_length = second->length();
1425 int length = first_length + second_length; 1425 int length = first_length + second_length;
1426 bool is_ascii = StringShape(first).IsAsciiRepresentation() 1426 bool is_ascii = first->IsAsciiRepresentation()
1427 && StringShape(second).IsAsciiRepresentation(); 1427 && second->IsAsciiRepresentation();
1428 1428
1429 // If the resulting string is small make a flat string. 1429 // If the resulting string is small make a flat string.
1430 if (length < String::kMinNonFlatLength) { 1430 if (length < String::kMinNonFlatLength) {
1431 ASSERT(first->IsFlat()); 1431 ASSERT(first->IsFlat());
1432 ASSERT(second->IsFlat()); 1432 ASSERT(second->IsFlat());
1433 if (is_ascii) { 1433 if (is_ascii) {
1434 Object* result = AllocateRawAsciiString(length); 1434 Object* result = AllocateRawAsciiString(length);
1435 if (result->IsFailure()) return result; 1435 if (result->IsFailure()) return result;
1436 // Copy the characters into the new object. 1436 // Copy the characters into the new object.
1437 char* dest = SeqAsciiString::cast(result)->GetChars(); 1437 char* dest = SeqAsciiString::cast(result)->GetChars();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 int end) { 1477 int end) {
1478 int length = end - start; 1478 int length = end - start;
1479 1479
1480 // If the resulting string is small make a sub string. 1480 // If the resulting string is small make a sub string.
1481 if (end - start <= String::kMinNonFlatLength) { 1481 if (end - start <= String::kMinNonFlatLength) {
1482 return Heap::AllocateSubString(buffer, start, end); 1482 return Heap::AllocateSubString(buffer, start, end);
1483 } 1483 }
1484 1484
1485 Map* map; 1485 Map* map;
1486 if (length <= String::kMaxShortStringSize) { 1486 if (length <= String::kMaxShortStringSize) {
1487 map = StringShape(buffer).IsAsciiRepresentation() ? 1487 map = buffer->IsAsciiRepresentation() ?
1488 short_sliced_ascii_string_map() : 1488 short_sliced_ascii_string_map() :
1489 short_sliced_string_map(); 1489 short_sliced_string_map();
1490 } else if (length <= String::kMaxMediumStringSize) { 1490 } else if (length <= String::kMaxMediumStringSize) {
1491 map = StringShape(buffer).IsAsciiRepresentation() ? 1491 map = buffer->IsAsciiRepresentation() ?
1492 medium_sliced_ascii_string_map() : 1492 medium_sliced_ascii_string_map() :
1493 medium_sliced_string_map(); 1493 medium_sliced_string_map();
1494 } else { 1494 } else {
1495 map = StringShape(buffer).IsAsciiRepresentation() ? 1495 map = buffer->IsAsciiRepresentation() ?
1496 long_sliced_ascii_string_map() : 1496 long_sliced_ascii_string_map() :
1497 long_sliced_string_map(); 1497 long_sliced_string_map();
1498 } 1498 }
1499 1499
1500 Object* result = Allocate(map, NEW_SPACE); 1500 Object* result = Allocate(map, NEW_SPACE);
1501 if (result->IsFailure()) return result; 1501 if (result->IsFailure()) return result;
1502 1502
1503 SlicedString* sliced_string = SlicedString::cast(result); 1503 SlicedString* sliced_string = SlicedString::cast(result);
1504 sliced_string->set_buffer(buffer); 1504 sliced_string->set_buffer(buffer);
1505 sliced_string->set_start(start); 1505 sliced_string->set_start(start);
(...skipping 11 matching lines...) Expand all
1517 if (length == 1) { 1517 if (length == 1) {
1518 return Heap::LookupSingleCharacterStringFromCode( 1518 return Heap::LookupSingleCharacterStringFromCode(
1519 buffer->Get(start)); 1519 buffer->Get(start));
1520 } 1520 }
1521 1521
1522 // Make an attempt to flatten the buffer to reduce access time. 1522 // Make an attempt to flatten the buffer to reduce access time.
1523 if (!buffer->IsFlat()) { 1523 if (!buffer->IsFlat()) {
1524 buffer->TryFlatten(); 1524 buffer->TryFlatten();
1525 } 1525 }
1526 1526
1527 Object* result = StringShape(buffer).IsAsciiRepresentation() 1527 Object* result = buffer->IsAsciiRepresentation()
1528 ? AllocateRawAsciiString(length) 1528 ? AllocateRawAsciiString(length)
1529 : AllocateRawTwoByteString(length); 1529 : AllocateRawTwoByteString(length);
1530 if (result->IsFailure()) return result; 1530 if (result->IsFailure()) return result;
1531 1531
1532 // Copy the characters into the new object. 1532 // Copy the characters into the new object.
1533 String* string_result = String::cast(result); 1533 String* string_result = String::cast(result);
1534 StringHasher hasher(length); 1534 StringHasher hasher(length);
1535 int i = 0; 1535 int i = 0;
1536 for (; i < length && hasher.is_array_index(); i++) { 1536 for (; i < length && hasher.is_array_index(); i++) {
1537 uc32 c = buffer->Get(start + i); 1537 uc32 c = buffer->Get(start + i);
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 #ifdef DEBUG 3387 #ifdef DEBUG
3388 bool Heap::GarbageCollectionGreedyCheck() { 3388 bool Heap::GarbageCollectionGreedyCheck() {
3389 ASSERT(FLAG_gc_greedy); 3389 ASSERT(FLAG_gc_greedy);
3390 if (Bootstrapper::IsActive()) return true; 3390 if (Bootstrapper::IsActive()) return true;
3391 if (disallow_allocation_failure()) return true; 3391 if (disallow_allocation_failure()) return true;
3392 return CollectGarbage(0, NEW_SPACE); 3392 return CollectGarbage(0, NEW_SPACE);
3393 } 3393 }
3394 #endif 3394 #endif
3395 3395
3396 } } // namespace v8::internal 3396 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/ia32/regexp-macro-assembler-ia32.cc » ('j') | src/objects-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698