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) const { | 2644 int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref) const { |
2645 if (IsDeadCheck("v8::String::WriteUtf8()")) return 0; | 2645 if (IsDeadCheck("v8::String::WriteUtf8()")) return 0; |
2646 LOG_API("String::WriteUtf8"); | 2646 LOG_API("String::WriteUtf8"); |
2647 ENTER_V8; | 2647 ENTER_V8; |
2648 i::Handle<i::String> str = Utils::OpenHandle(this); | 2648 i::Handle<i::String> str = Utils::OpenHandle(this); |
2649 StringTracker::RecordWrite(str); | 2649 StringTracker::RecordWrite(str); |
2650 write_input_buffer.Reset(0, *str); | 2650 write_input_buffer.Reset(0, *str); |
2651 int len = str->length(); | 2651 int len = str->length(); |
2652 // Encode the first K - 3 bytes directly into the buffer since we | 2652 // 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 | 2653 // know there's room for them. If no capacity is given we copy all |
2654 // of them here. | 2654 // of them here. |
2655 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); | 2655 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); |
2656 int i; | 2656 int i; |
2657 int pos = 0; | 2657 int pos = 0; |
| 2658 int nchars = 0; |
2658 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { | 2659 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { |
2659 i::uc32 c = write_input_buffer.GetNext(); | 2660 i::uc32 c = write_input_buffer.GetNext(); |
2660 int written = unibrow::Utf8::Encode(buffer + pos, c); | 2661 int written = unibrow::Utf8::Encode(buffer + pos, c); |
2661 pos += written; | 2662 pos += written; |
| 2663 nchars++; |
2662 } | 2664 } |
2663 if (i < len) { | 2665 if (i < len) { |
2664 // For the last characters we need to check the length for each one | 2666 // For the last characters we need to check the length for each one |
2665 // because they may be longer than the remaining space in the | 2667 // because they may be longer than the remaining space in the |
2666 // buffer. | 2668 // buffer. |
2667 char intermediate[unibrow::Utf8::kMaxEncodedSize]; | 2669 char intermediate[unibrow::Utf8::kMaxEncodedSize]; |
2668 for (; i < len && pos < capacity; i++) { | 2670 for (; i < len && pos < capacity; i++) { |
2669 i::uc32 c = write_input_buffer.GetNext(); | 2671 i::uc32 c = write_input_buffer.GetNext(); |
2670 int written = unibrow::Utf8::Encode(intermediate, c); | 2672 int written = unibrow::Utf8::Encode(intermediate, c); |
2671 if (pos + written <= capacity) { | 2673 if (pos + written <= capacity) { |
2672 for (int j = 0; j < written; j++) | 2674 for (int j = 0; j < written; j++) |
2673 buffer[pos + j] = intermediate[j]; | 2675 buffer[pos + j] = intermediate[j]; |
2674 pos += written; | 2676 pos += written; |
| 2677 nchars++; |
2675 } else { | 2678 } else { |
2676 // We've reached the end of the buffer | 2679 // We've reached the end of the buffer |
2677 break; | 2680 break; |
2678 } | 2681 } |
2679 } | 2682 } |
2680 } | 2683 } |
| 2684 if (nchars_ref != NULL) *nchars_ref = nchars; |
2681 if (i == len && (capacity == -1 || pos < capacity)) | 2685 if (i == len && (capacity == -1 || pos < capacity)) |
2682 buffer[pos++] = '\0'; | 2686 buffer[pos++] = '\0'; |
2683 return pos; | 2687 return pos; |
2684 } | 2688 } |
2685 | 2689 |
2686 | 2690 |
2687 int String::WriteAscii(char* buffer, int start, int length) const { | 2691 int String::WriteAscii(char* buffer, int start, int length) const { |
2688 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; | 2692 if (IsDeadCheck("v8::String::WriteAscii()")) return 0; |
2689 LOG_API("String::WriteAscii"); | 2693 LOG_API("String::WriteAscii"); |
2690 ENTER_V8; | 2694 ENTER_V8; |
(...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4200 | 4204 |
4201 | 4205 |
4202 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { | 4206 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { |
4203 HandleScopeImplementer* thread_local = | 4207 HandleScopeImplementer* thread_local = |
4204 reinterpret_cast<HandleScopeImplementer*>(storage); | 4208 reinterpret_cast<HandleScopeImplementer*>(storage); |
4205 thread_local->IterateThis(v); | 4209 thread_local->IterateThis(v); |
4206 return storage + ArchiveSpacePerThread(); | 4210 return storage + ArchiveSpacePerThread(); |
4207 } | 4211 } |
4208 | 4212 |
4209 } } // namespace v8::internal | 4213 } } // namespace v8::internal |
OLD | NEW |