Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: src/api.cc

Issue 8390004: Improve WriteUtf8 and WriteAscii. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed heuristic for flattening Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 3624 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 3635
3636 int String::WriteUtf8(char* buffer, 3636 int String::WriteUtf8(char* buffer,
3637 int capacity, 3637 int capacity,
3638 int* nchars_ref, 3638 int* nchars_ref,
3639 int options) const { 3639 int options) const {
3640 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3640 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3641 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; 3641 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
3642 LOG_API(isolate, "String::WriteUtf8"); 3642 LOG_API(isolate, "String::WriteUtf8");
3643 ENTER_V8(isolate); 3643 ENTER_V8(isolate);
3644 i::Handle<i::String> str = Utils::OpenHandle(this); 3644 i::Handle<i::String> str = Utils::OpenHandle(this);
3645 if (options & HINT_MANY_WRITES_EXPECTED) {
3646 // Flatten the string for efficiency. This applies whether we are
3647 // using StringInputBuffer or Get(i) to access the characters.
3648 FlattenString(str);
3649 }
3645 if (str->IsAsciiRepresentation()) { 3650 if (str->IsAsciiRepresentation()) {
3646 int len; 3651 int len;
3647 if (capacity == -1) { 3652 if (capacity == -1) {
3648 capacity = str->length() + 1; 3653 capacity = str->length() + 1;
3649 len = str->length(); 3654 len = str->length();
3650 } else { 3655 } else {
3651 len = i::Min(capacity, str->length()); 3656 len = i::Min(capacity, str->length());
3652 } 3657 }
3653 i::String::WriteToFlat(*str, buffer, 0, len); 3658 i::String::WriteToFlat(*str, buffer, 0, len);
3654 if (nchars_ref != NULL) *nchars_ref = len; 3659 if (nchars_ref != NULL) *nchars_ref = len;
3655 if (!(options & NO_NULL_TERMINATION) && capacity > len) { 3660 if (!(options & NO_NULL_TERMINATION) && capacity > len) {
3656 buffer[len] = '\0'; 3661 buffer[len] = '\0';
3657 return len + 1; 3662 return len + 1;
3658 } 3663 }
3659 return len; 3664 return len;
3660 } 3665 }
3661 3666
3662 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); 3667 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3663 isolate->string_tracker()->RecordWrite(str); 3668 isolate->string_tracker()->RecordWrite(str);
3664 if (options & HINT_MANY_WRITES_EXPECTED) { 3669
3665 // Flatten the string for efficiency. This applies whether we are
3666 // using StringInputBuffer or Get(i) to access the characters.
3667 FlattenString(str);
3668 }
3669 write_input_buffer.Reset(0, *str); 3670 write_input_buffer.Reset(0, *str);
3670 int len = str->length(); 3671 int len = str->length();
3671 // Encode the first K - 3 bytes directly into the buffer since we 3672 // Encode the first K - 3 bytes directly into the buffer since we
3672 // know there's room for them. If no capacity is given we copy all 3673 // know there's room for them. If no capacity is given we copy all
3673 // of them here. 3674 // of them here.
3674 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); 3675 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1);
3675 int i; 3676 int i;
3676 int pos = 0; 3677 int pos = 0;
3677 int nchars = 0; 3678 int nchars = 0;
3678 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) { 3679 for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0; 3717 if (IsDeadCheck(isolate, "v8::String::WriteAscii()")) return 0;
3717 LOG_API(isolate, "String::WriteAscii"); 3718 LOG_API(isolate, "String::WriteAscii");
3718 ENTER_V8(isolate); 3719 ENTER_V8(isolate);
3719 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); 3720 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3720 ASSERT(start >= 0 && length >= -1); 3721 ASSERT(start >= 0 && length >= -1);
3721 i::Handle<i::String> str = Utils::OpenHandle(this); 3722 i::Handle<i::String> str = Utils::OpenHandle(this);
3722 isolate->string_tracker()->RecordWrite(str); 3723 isolate->string_tracker()->RecordWrite(str);
3723 if (options & HINT_MANY_WRITES_EXPECTED) { 3724 if (options & HINT_MANY_WRITES_EXPECTED) {
3724 // Flatten the string for efficiency. This applies whether we are 3725 // Flatten the string for efficiency. This applies whether we are
3725 // using StringInputBuffer or Get(i) to access the characters. 3726 // using StringInputBuffer or Get(i) to access the characters.
3726 str->TryFlatten(); 3727 FlattenString(str);
3727 } 3728 }
3729 if (str->IsAsciiRepresentation()) {
3730 if (length == -1) length = str->length() + 1;
3731 int len = i::Min(length, str->length() - start);
3732 i::String::WriteToFlat(*str, buffer, start, start + len);
3733 for (int i = 0; i < len; i++) {
3734 if (buffer[i] == '\0') buffer[i] = ' ';
3735 }
3736 if (!(options & NO_NULL_TERMINATION) && length > len) {
3737 buffer[len] = '\0';
3738 }
3739 return len;
3740 }
3741
3728 int end = length; 3742 int end = length;
3729 if ( (length == -1) || (length > str->length() - start) ) 3743 if ( (length == -1) || (length > str->length() - start) )
3730 end = str->length() - start; 3744 end = str->length() - start;
3731 if (end < 0) return 0; 3745 if (end < 0) return 0;
3732 write_input_buffer.Reset(start, *str); 3746 write_input_buffer.Reset(start, *str);
3733 int i; 3747 int i;
3734 for (i = 0; i < end; i++) { 3748 for (i = 0; i < end; i++) {
3735 char c = static_cast<char>(write_input_buffer.GetNext()); 3749 char c = static_cast<char>(write_input_buffer.GetNext());
3736 if (c == '\0') c = ' '; 3750 if (c == '\0') c = ' ';
3737 buffer[i] = c; 3751 buffer[i] = c;
(...skipping 11 matching lines...) Expand all
3749 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3763 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3750 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0; 3764 if (IsDeadCheck(isolate, "v8::String::Write()")) return 0;
3751 LOG_API(isolate, "String::Write"); 3765 LOG_API(isolate, "String::Write");
3752 ENTER_V8(isolate); 3766 ENTER_V8(isolate);
3753 ASSERT(start >= 0 && length >= -1); 3767 ASSERT(start >= 0 && length >= -1);
3754 i::Handle<i::String> str = Utils::OpenHandle(this); 3768 i::Handle<i::String> str = Utils::OpenHandle(this);
3755 isolate->string_tracker()->RecordWrite(str); 3769 isolate->string_tracker()->RecordWrite(str);
3756 if (options & HINT_MANY_WRITES_EXPECTED) { 3770 if (options & HINT_MANY_WRITES_EXPECTED) {
3757 // Flatten the string for efficiency. This applies whether we are 3771 // Flatten the string for efficiency. This applies whether we are
3758 // using StringInputBuffer or Get(i) to access the characters. 3772 // using StringInputBuffer or Get(i) to access the characters.
3759 str->TryFlatten(); 3773 FlattenString(str);
3760 } 3774 }
3761 int end = start + length; 3775 int end = start + length;
3762 if ((length == -1) || (length > str->length() - start) ) 3776 if ((length == -1) || (length > str->length() - start) )
3763 end = str->length(); 3777 end = str->length();
3764 if (end < 0) return 0; 3778 if (end < 0) return 0;
3765 i::String::WriteToFlat(*str, buffer, start, end); 3779 i::String::WriteToFlat(*str, buffer, start, end);
3766 if (!(options & NO_NULL_TERMINATION) && 3780 if (!(options & NO_NULL_TERMINATION) &&
3767 (length == -1 || end - start < length)) { 3781 (length == -1 || end - start < length)) {
3768 buffer[end - start] = '\0'; 3782 buffer[end - start] = '\0';
3769 } 3783 }
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after
6100 6114
6101 6115
6102 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6116 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6103 HandleScopeImplementer* scope_implementer = 6117 HandleScopeImplementer* scope_implementer =
6104 reinterpret_cast<HandleScopeImplementer*>(storage); 6118 reinterpret_cast<HandleScopeImplementer*>(storage);
6105 scope_implementer->IterateThis(v); 6119 scope_implementer->IterateThis(v);
6106 return storage + ArchiveSpacePerThread(); 6120 return storage + ArchiveSpacePerThread();
6107 } 6121 }
6108 6122
6109 } } // namespace v8::internal 6123 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698