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 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 return SingleCharIndexOf(sub->ToAsciiVector(), pat->Get(0), start_index); | 1349 return SingleCharIndexOf(sub->ToAsciiVector(), pat->Get(0), start_index); |
1350 } | 1350 } |
1351 return SingleCharIndexOf(sub->ToUC16Vector(), pat->Get(0), start_index); | 1351 return SingleCharIndexOf(sub->ToUC16Vector(), pat->Get(0), start_index); |
1352 } | 1352 } |
1353 | 1353 |
1354 FlattenString(pat); | 1354 FlattenString(pat); |
1355 | 1355 |
1356 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid | 1356 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid |
1357 // dispatch on type of strings | 1357 // dispatch on type of strings |
1358 if (pat->is_ascii_representation()) { | 1358 if (pat->is_ascii_representation()) { |
1359 Vector<const char> pat_vector = pat->ToAsciiVector(); | 1359 Vector<const byte> pat_vector = pat->ToAsciiVector(); |
1360 if (sub->is_ascii_representation()) { | 1360 if (sub->is_ascii_representation()) { |
1361 return StringMatchStrategy(sub->ToAsciiVector(), pat_vector, start_index); | 1361 return StringMatchStrategy(sub->ToAsciiVector(), pat_vector, start_index); |
1362 } | 1362 } |
1363 return StringMatchStrategy(sub->ToUC16Vector(), pat_vector, start_index); | 1363 return StringMatchStrategy(sub->ToUC16Vector(), pat_vector, start_index); |
1364 } | 1364 } |
1365 Vector<const uc16> pat_vector = pat->ToUC16Vector(); | 1365 Vector<const uc16> pat_vector = pat->ToUC16Vector(); |
1366 if (sub->is_ascii_representation()) { | 1366 if (sub->is_ascii_representation()) { |
1367 return StringMatchStrategy(sub->ToAsciiVector(), pat_vector, start_index); | 1367 return StringMatchStrategy(sub->ToAsciiVector(), pat_vector, start_index); |
1368 } | 1368 } |
1369 return StringMatchStrategy(sub->ToUC16Vector(), pat_vector, start_index); | 1369 return StringMatchStrategy(sub->ToUC16Vector(), pat_vector, start_index); |
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2584 // Make sure that an out of memory exception is thrown if the length | 2584 // Make sure that an out of memory exception is thrown if the length |
2585 // of the new cons string is too large to fit in a Smi. | 2585 // of the new cons string is too large to fit in a Smi. |
2586 if (length_sum > Smi::kMaxValue || length_sum < 0) { | 2586 if (length_sum > Smi::kMaxValue || length_sum < 0) { |
2587 Top::context()->mark_out_of_memory(); | 2587 Top::context()->mark_out_of_memory(); |
2588 return Failure::OutOfMemoryException(); | 2588 return Failure::OutOfMemoryException(); |
2589 } | 2589 } |
2590 return Heap::AllocateConsString(str1, str2); | 2590 return Heap::AllocateConsString(str1, str2); |
2591 } | 2591 } |
2592 | 2592 |
2593 | 2593 |
| 2594 template<typename sinkchar> |
| 2595 static inline void StringBuilderConcatHelper(String* special, sinkchar* sink, Fi
xedArray* fixed_array, int array_length) { |
| 2596 int position = 0; |
| 2597 for (int i = 0; i < array_length; i++) { |
| 2598 Object* element = fixed_array->get(i); |
| 2599 if (element->IsSmi()) { |
| 2600 int len = Smi::cast(element)->value(); |
| 2601 int pos = len >> 11; |
| 2602 len &= 0x7ff; |
| 2603 String::WriteToFlat(special, sink + position, pos, pos + len); |
| 2604 position += len; |
| 2605 } else { |
| 2606 String* string = String::cast(element); |
| 2607 int element_length = string->length(); |
| 2608 String::WriteToFlat(string, sink + position, 0, element_length); |
| 2609 position += element_length; |
| 2610 } |
| 2611 } |
| 2612 } |
| 2613 |
| 2614 |
2594 static Object* Runtime_StringBuilderConcat(Arguments args) { | 2615 static Object* Runtime_StringBuilderConcat(Arguments args) { |
2595 NoHandleAllocation ha; | 2616 NoHandleAllocation ha; |
2596 ASSERT(args.length() == 2); | 2617 ASSERT(args.length() == 2); |
2597 CONVERT_CHECKED(JSArray, array, args[0]); | 2618 CONVERT_CHECKED(JSArray, array, args[0]); |
2598 CONVERT_CHECKED(String, special, args[1]); | 2619 CONVERT_CHECKED(String, special, args[1]); |
2599 int special_length = special->length(); | 2620 int special_length = special->length(); |
2600 Object* smi_array_length = array->length(); | 2621 Object* smi_array_length = array->length(); |
2601 if (!smi_array_length->IsSmi()) { | 2622 if (!smi_array_length->IsSmi()) { |
2602 Top::context()->mark_out_of_memory(); | 2623 Top::context()->mark_out_of_memory(); |
2603 return Failure::OutOfMemoryException(); | 2624 return Failure::OutOfMemoryException(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 position += element_length; | 2661 position += element_length; |
2641 if (ascii && !element->IsAsciiRepresentation()) { | 2662 if (ascii && !element->IsAsciiRepresentation()) { |
2642 ascii = false; | 2663 ascii = false; |
2643 } | 2664 } |
2644 } else { | 2665 } else { |
2645 return Top::Throw(Heap::illegal_argument_symbol()); | 2666 return Top::Throw(Heap::illegal_argument_symbol()); |
2646 } | 2667 } |
2647 } | 2668 } |
2648 | 2669 |
2649 int length = position; | 2670 int length = position; |
2650 position = 0; | |
2651 Object* object; | 2671 Object* object; |
| 2672 |
2652 if (ascii) { | 2673 if (ascii) { |
2653 object = Heap::AllocateRawAsciiString(length); | 2674 object = Heap::AllocateRawAsciiString(length); |
| 2675 if (object->IsFailure()) return object; |
| 2676 SeqAsciiString* answer = SeqAsciiString::cast(object); |
| 2677 StringBuilderConcatHelper(special, |
| 2678 answer->GetCharsAddress(), |
| 2679 fixed_array, |
| 2680 array_length); |
| 2681 return answer; |
2654 } else { | 2682 } else { |
2655 object = Heap::AllocateRawTwoByteString(length); | 2683 object = Heap::AllocateRawTwoByteString(length); |
| 2684 if (object->IsFailure()) return object; |
| 2685 SeqTwoByteString* answer = SeqTwoByteString::cast(object); |
| 2686 StringBuilderConcatHelper(special, |
| 2687 reinterpret_cast<uc16*>(answer->GetCharsAddress())
, |
| 2688 fixed_array, |
| 2689 array_length); |
| 2690 return answer; |
2656 } | 2691 } |
2657 if (object->IsFailure()) return object; | |
2658 | |
2659 String* answer = String::cast(object); | |
2660 for (int i = 0; i < array_length; i++) { | |
2661 Object* element = fixed_array->get(i); | |
2662 if (element->IsSmi()) { | |
2663 int len = Smi::cast(element)->value(); | |
2664 int pos = len >> 11; | |
2665 len &= 0x7ff; | |
2666 String::Flatten(special, answer, pos, pos + len, position); | |
2667 position += len; | |
2668 } else { | |
2669 String* string = String::cast(element); | |
2670 int element_length = string->length(); | |
2671 String::Flatten(string, answer, 0, element_length, position); | |
2672 position += element_length; | |
2673 } | |
2674 } | |
2675 return answer; | |
2676 } | 2692 } |
2677 | 2693 |
2678 | 2694 |
2679 static Object* Runtime_NumberOr(Arguments args) { | 2695 static Object* Runtime_NumberOr(Arguments args) { |
2680 NoHandleAllocation ha; | 2696 NoHandleAllocation ha; |
2681 ASSERT(args.length() == 2); | 2697 ASSERT(args.length() == 2); |
2682 | 2698 |
2683 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); | 2699 CONVERT_NUMBER_CHECKED(int32_t, x, Int32, args[0]); |
2684 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); | 2700 CONVERT_NUMBER_CHECKED(int32_t, y, Int32, args[1]); |
2685 return Heap::NumberFromInt32(x | y); | 2701 return Heap::NumberFromInt32(x | y); |
(...skipping 2761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5447 | 5463 |
5448 void Runtime::PerformGC(Object* result) { | 5464 void Runtime::PerformGC(Object* result) { |
5449 Failure* failure = Failure::cast(result); | 5465 Failure* failure = Failure::cast(result); |
5450 // Try to do a garbage collection; ignore it if it fails. The C | 5466 // Try to do a garbage collection; ignore it if it fails. The C |
5451 // entry stub will throw an out-of-memory exception in that case. | 5467 // entry stub will throw an out-of-memory exception in that case. |
5452 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); | 5468 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); |
5453 } | 5469 } |
5454 | 5470 |
5455 | 5471 |
5456 } } // namespace v8::internal | 5472 } } // namespace v8::internal |
OLD | NEW |