Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1529 share->set_instance_class_name(Object_symbol()); | 1529 share->set_instance_class_name(Object_symbol()); |
| 1530 share->set_function_data(undefined_value()); | 1530 share->set_function_data(undefined_value()); |
| 1531 share->set_script(undefined_value()); | 1531 share->set_script(undefined_value()); |
| 1532 share->set_start_position_and_type(0); | 1532 share->set_start_position_and_type(0); |
| 1533 share->set_debug_info(undefined_value()); | 1533 share->set_debug_info(undefined_value()); |
| 1534 share->set_inferred_name(empty_string()); | 1534 share->set_inferred_name(empty_string()); |
| 1535 return result; | 1535 return result; |
| 1536 } | 1536 } |
| 1537 | 1537 |
| 1538 | 1538 |
| 1539 Object* Heap::AllocateConsString(String* first, | 1539 Object* Heap::AllocateConsString(String* first, String* second) { |
| 1540 String* second) { | |
| 1541 int first_length = first->length(); | 1540 int first_length = first->length(); |
| 1541 if (first_length == 0) return second; | |
| 1542 | |
| 1542 int second_length = second->length(); | 1543 int second_length = second->length(); |
| 1544 if (second_length == 0) return first; | |
| 1545 | |
| 1543 int length = first_length + second_length; | 1546 int length = first_length + second_length; |
| 1544 bool is_ascii = first->IsAsciiRepresentation() | 1547 bool is_ascii = first->IsAsciiRepresentation() |
| 1545 && second->IsAsciiRepresentation(); | 1548 && second->IsAsciiRepresentation(); |
| 1546 | 1549 |
| 1550 // Make sure that an out of memory exception is thrown if the length | |
| 1551 // of the new cons string is too large to fit in a Smi. | |
| 1552 if (length > Smi::kMaxValue || length < -0) { | |
| 1553 Top::context()->mark_out_of_memory(); | |
| 1554 return Failure::OutOfMemoryException(); | |
| 1555 } | |
| 1556 | |
| 1547 // If the resulting string is small make a flat string. | 1557 // If the resulting string is small make a flat string. |
| 1548 if (length < String::kMinNonFlatLength) { | 1558 if (length < String::kMinNonFlatLength) { |
| 1549 ASSERT(first->IsFlat()); | 1559 ASSERT(first->IsFlat()); |
| 1550 ASSERT(second->IsFlat()); | 1560 ASSERT(second->IsFlat()); |
| 1551 if (is_ascii) { | 1561 if (is_ascii) { |
| 1552 Object* result = AllocateRawAsciiString(length); | 1562 Object* result = AllocateRawAsciiString(length); |
| 1553 if (result->IsFailure()) return result; | 1563 if (result->IsFailure()) return result; |
| 1554 // Copy the characters into the new object. | 1564 // Copy the characters into the new object. |
| 1555 char* dest = SeqAsciiString::cast(result)->GetChars(); | 1565 char* dest = SeqAsciiString::cast(result)->GetChars(); |
| 1556 String::WriteToFlat(first, dest, 0, first_length); | 1566 // Copy first part. |
| 1557 String::WriteToFlat(second, dest + first_length, 0, second_length); | 1567 char* src = SeqAsciiString::cast(first)->GetChars(); |
|
Kasper Lund
2009/06/26 13:07:23
Remove extra space after src
| |
| 1568 for (int i = 0; i < first_length; i++) *dest++ = src[i]; | |
| 1569 // Copy second part. | |
| 1570 src = SeqAsciiString::cast(second)->GetChars(); | |
|
Kasper Lund
2009/06/26 13:07:23
Remove extra space after src.
| |
| 1571 for (int i = 0; i < second_length; i++) *dest++ = src[i]; | |
| 1558 return result; | 1572 return result; |
| 1559 } else { | 1573 } else { |
| 1560 Object* result = AllocateRawTwoByteString(length); | 1574 Object* result = AllocateRawTwoByteString(length); |
| 1561 if (result->IsFailure()) return result; | 1575 if (result->IsFailure()) return result; |
| 1562 // Copy the characters into the new object. | 1576 // Copy the characters into the new object. |
| 1563 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); | 1577 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); |
| 1564 String::WriteToFlat(first, dest, 0, first_length); | 1578 String::WriteToFlat(first, dest, 0, first_length); |
| 1565 String::WriteToFlat(second, dest + first_length, 0, second_length); | 1579 String::WriteToFlat(second, dest + first_length, 0, second_length); |
| 1566 return result; | 1580 return result; |
| 1567 } | 1581 } |
| (...skipping 2012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3580 #ifdef DEBUG | 3594 #ifdef DEBUG |
| 3581 bool Heap::GarbageCollectionGreedyCheck() { | 3595 bool Heap::GarbageCollectionGreedyCheck() { |
| 3582 ASSERT(FLAG_gc_greedy); | 3596 ASSERT(FLAG_gc_greedy); |
| 3583 if (Bootstrapper::IsActive()) return true; | 3597 if (Bootstrapper::IsActive()) return true; |
| 3584 if (disallow_allocation_failure()) return true; | 3598 if (disallow_allocation_failure()) return true; |
| 3585 return CollectGarbage(0, NEW_SPACE); | 3599 return CollectGarbage(0, NEW_SPACE); |
| 3586 } | 3600 } |
| 3587 #endif | 3601 #endif |
| 3588 | 3602 |
| 3589 } } // namespace v8::internal | 3603 } } // namespace v8::internal |
| OLD | NEW |