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 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2634 return Utils::OpenHandle(this)->length(); | 2634 return Utils::OpenHandle(this)->length(); |
2635 } | 2635 } |
2636 | 2636 |
2637 | 2637 |
2638 int String::Utf8Length() const { | 2638 int String::Utf8Length() const { |
2639 if (IsDeadCheck("v8::String::Utf8Length()")) return 0; | 2639 if (IsDeadCheck("v8::String::Utf8Length()")) return 0; |
2640 return Utils::OpenHandle(this)->Utf8Length(); | 2640 return Utils::OpenHandle(this)->Utf8Length(); |
2641 } | 2641 } |
2642 | 2642 |
2643 | 2643 |
2644 int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref) const { | 2644 int String::WriteUtf8(char* buffer, |
| 2645 int capacity, |
| 2646 int* nchars_ref, |
| 2647 WriteHints hints) const { |
2645 if (IsDeadCheck("v8::String::WriteUtf8()")) return 0; | 2648 if (IsDeadCheck("v8::String::WriteUtf8()")) return 0; |
2646 LOG_API("String::WriteUtf8"); | 2649 LOG_API("String::WriteUtf8"); |
2647 ENTER_V8; | 2650 ENTER_V8; |
2648 i::Handle<i::String> str = Utils::OpenHandle(this); | 2651 i::Handle<i::String> str = Utils::OpenHandle(this); |
2649 StringTracker::RecordWrite(str); | 2652 StringTracker::RecordWrite(str); |
| 2653 if (hints & HINT_MANY_WRITES_EXPECTED) { |
| 2654 // Flatten the string for efficiency. This applies whether we are |
| 2655 // using StringInputBuffer or Get(i) to access the characters. |
| 2656 str->TryFlatten(); |
| 2657 } |
2650 write_input_buffer.Reset(0, *str); | 2658 write_input_buffer.Reset(0, *str); |
2651 int len = str->length(); | 2659 int len = str->length(); |
2652 // Encode the first K - 3 bytes directly into the buffer since we | 2660 // Encode the first K - 3 bytes directly into the buffer since we |
2653 // know there's room for them. If no capacity is given we copy all | 2661 // know there's room for them. If no capacity is given we copy all |
2654 // of them here. | 2662 // of them here. |
2655 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); | 2663 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); |
2656 int i; | 2664 int i; |
2657 int pos = 0; | 2665 int pos = 0; |
2658 int nchars = 0; | 2666 int nchars = 0; |
2659 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { | 2667 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { |
(...skipping 21 matching lines...) Expand all Loading... |
2681 } | 2689 } |
2682 } | 2690 } |
2683 } | 2691 } |
2684 if (nchars_ref != NULL) *nchars_ref = nchars; | 2692 if (nchars_ref != NULL) *nchars_ref = nchars; |
2685 if (i == len && (capacity == -1 || pos < capacity)) | 2693 if (i == len && (capacity == -1 || pos < capacity)) |
2686 buffer[pos++] = '\0'; | 2694 buffer[pos++] = '\0'; |
2687 return pos; | 2695 return pos; |
2688 } | 2696 } |
2689 | 2697 |
2690 | 2698 |
2691 int String::WriteAscii(char* buffer, int start, int length) const { | 2699 int String::WriteAscii(char* buffer, |
| 2700 int start, |
| 2701 int length, |
| 2702 WriteHints hints) const { |
2692 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; | 2703 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; |
2693 LOG_API("String::WriteAscii"); | 2704 LOG_API("String::WriteAscii"); |
2694 ENTER_V8; | 2705 ENTER_V8; |
2695 ASSERT(start >= 0 && length >= -1); | 2706 ASSERT(start >= 0 && length >= -1); |
2696 i::Handle<i::String> str = Utils::OpenHandle(this); | 2707 i::Handle<i::String> str = Utils::OpenHandle(this); |
2697 StringTracker::RecordWrite(str); | 2708 StringTracker::RecordWrite(str); |
2698 // Flatten the string for efficiency. This applies whether we are | 2709 if (hints & HINT_MANY_WRITES_EXPECTED) { |
2699 // using StringInputBuffer or Get(i) to access the characters. | 2710 // Flatten the string for efficiency. This applies whether we are |
2700 str->TryFlatten(); | 2711 // using StringInputBuffer or Get(i) to access the characters. |
| 2712 str->TryFlatten(); |
| 2713 } |
2701 int end = length; | 2714 int end = length; |
2702 if ( (length == -1) || (length > str->length() - start) ) | 2715 if ( (length == -1) || (length > str->length() - start) ) |
2703 end = str->length() - start; | 2716 end = str->length() - start; |
2704 if (end < 0) return 0; | 2717 if (end < 0) return 0; |
2705 write_input_buffer.Reset(start, *str); | 2718 write_input_buffer.Reset(start, *str); |
2706 int i; | 2719 int i; |
2707 for (i = 0; i < end; i++) { | 2720 for (i = 0; i < end; i++) { |
2708 char c = static_cast<char>(write_input_buffer.GetNext()); | 2721 char c = static_cast<char>(write_input_buffer.GetNext()); |
2709 if (c == '\0') c = ' '; | 2722 if (c == '\0') c = ' '; |
2710 buffer[i] = c; | 2723 buffer[i] = c; |
2711 } | 2724 } |
2712 if (length == -1 || i < length) | 2725 if (length == -1 || i < length) |
2713 buffer[i] = '\0'; | 2726 buffer[i] = '\0'; |
2714 return i; | 2727 return i; |
2715 } | 2728 } |
2716 | 2729 |
2717 | 2730 |
2718 int String::Write(uint16_t* buffer, int start, int length) const { | 2731 int String::Write(uint16_t* buffer, |
| 2732 int start, |
| 2733 int length, |
| 2734 WriteHints hints) const { |
2719 if (IsDeadCheck("v8::String::Write()")) return 0; | 2735 if (IsDeadCheck("v8::String::Write()")) return 0; |
2720 LOG_API("String::Write"); | 2736 LOG_API("String::Write"); |
2721 ENTER_V8; | 2737 ENTER_V8; |
2722 ASSERT(start >= 0 && length >= -1); | 2738 ASSERT(start >= 0 && length >= -1); |
2723 i::Handle<i::String> str = Utils::OpenHandle(this); | 2739 i::Handle<i::String> str = Utils::OpenHandle(this); |
2724 StringTracker::RecordWrite(str); | 2740 StringTracker::RecordWrite(str); |
| 2741 if (hints & HINT_MANY_WRITES_EXPECTED) { |
| 2742 // Flatten the string for efficiency. This applies whether we are |
| 2743 // using StringInputBuffer or Get(i) to access the characters. |
| 2744 str->TryFlatten(); |
| 2745 } |
2725 int end = length; | 2746 int end = length; |
2726 if ( (length == -1) || (length > str->length() - start) ) | 2747 if ( (length == -1) || (length > str->length() - start) ) |
2727 end = str->length() - start; | 2748 end = str->length() - start; |
2728 if (end < 0) return 0; | 2749 if (end < 0) return 0; |
2729 i::String::WriteToFlat(*str, buffer, start, end); | 2750 i::String::WriteToFlat(*str, buffer, start, end); |
2730 if (length == -1 || end < length) | 2751 if (length == -1 || end < length) |
2731 buffer[end] = '\0'; | 2752 buffer[end] = '\0'; |
2732 return end; | 2753 return end; |
2733 } | 2754 } |
2734 | 2755 |
2735 | 2756 |
2736 void v8::String::Flatten() { | |
2737 if (IsDeadCheck("v8::String::Flatten()")) return; | |
2738 i::Handle<i::String> str = Utils::OpenHandle(this); | |
2739 i::FlattenString(str); | |
2740 } | |
2741 | |
2742 | |
2743 bool v8::String::IsExternal() const { | 2757 bool v8::String::IsExternal() const { |
2744 EnsureInitialized("v8::String::IsExternal()"); | 2758 EnsureInitialized("v8::String::IsExternal()"); |
2745 i::Handle<i::String> str = Utils::OpenHandle(this); | 2759 i::Handle<i::String> str = Utils::OpenHandle(this); |
2746 return i::StringShape(*str).IsExternalTwoByte(); | 2760 return i::StringShape(*str).IsExternalTwoByte(); |
2747 } | 2761 } |
2748 | 2762 |
2749 | 2763 |
2750 bool v8::String::IsExternalAscii() const { | 2764 bool v8::String::IsExternalAscii() const { |
2751 EnsureInitialized("v8::String::IsExternalAscii()"); | 2765 EnsureInitialized("v8::String::IsExternalAscii()"); |
2752 i::Handle<i::String> str = Utils::OpenHandle(this); | 2766 i::Handle<i::String> str = Utils::OpenHandle(this); |
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4213 | 4227 |
4214 | 4228 |
4215 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 4229 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
4216 HandleScopeImplementer* thread_local = | 4230 HandleScopeImplementer* thread_local = |
4217 reinterpret_cast<HandleScopeImplementer*>(storage); | 4231 reinterpret_cast<HandleScopeImplementer*>(storage); |
4218 thread_local->IterateThis(v); | 4232 thread_local->IterateThis(v); |
4219 return storage + ArchiveSpacePerThread(); | 4233 return storage + ArchiveSpacePerThread(); |
4220 } | 4234 } |
4221 | 4235 |
4222 } } // namespace v8::internal | 4236 } } // namespace v8::internal |
OLD | NEW |