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