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

Side by Side Diff: src/api.cc

Issue 9536018: Faster WriteUtf8 for medium size strings? Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 years, 9 months 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 | src/objects.h » ('j') | src/objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 3684 matching lines...) Expand 10 before | Expand all | Expand 10 after
3695 3695
3696 int String::WriteUtf8(char* buffer, 3696 int String::WriteUtf8(char* buffer,
3697 int capacity, 3697 int capacity,
3698 int* nchars_ref, 3698 int* nchars_ref,
3699 int options) const { 3699 int options) const {
3700 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3700 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3701 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; 3701 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
3702 LOG_API(isolate, "String::WriteUtf8"); 3702 LOG_API(isolate, "String::WriteUtf8");
3703 ENTER_V8(isolate); 3703 ENTER_V8(isolate);
3704 i::Handle<i::String> str = Utils::OpenHandle(this); 3704 i::Handle<i::String> str = Utils::OpenHandle(this);
3705 int string_length = str->length();
3705 if (str->IsAsciiRepresentation()) { 3706 if (str->IsAsciiRepresentation()) {
3706 int len; 3707 int len;
3707 if (capacity == -1) { 3708 if (capacity == -1) {
3708 capacity = str->length() + 1; 3709 capacity = str->length() + 1;
3709 len = str->length(); 3710 len = string_length;
3710 } else { 3711 } else {
3711 len = i::Min(capacity, str->length()); 3712 len = i::Min(capacity, str->length());
3712 } 3713 }
3713 i::String::WriteToFlat(*str, buffer, 0, len); 3714 i::String::WriteToFlat(*str, buffer, 0, len);
3714 if (nchars_ref != NULL) *nchars_ref = len; 3715 if (nchars_ref != NULL) *nchars_ref = len;
3715 if (!(options & NO_NULL_TERMINATION) && capacity > len) { 3716 if (!(options & NO_NULL_TERMINATION) && capacity > len) {
3716 buffer[len] = '\0'; 3717 buffer[len] = '\0';
3717 return len + 1; 3718 return len + 1;
3718 } 3719 }
3719 return len; 3720 return len;
3720 } 3721 }
3721 3722
3723 if (capacity == -1 || capacity >= string_length * 3) {
3724 if (string_length < 100) {
3725 int utf8_bytes =
3726 str->RecursivelySerializeToUtf8(buffer, 0, string_length);
3727 if ((options & NO_NULL_TERMINATION) == 0 &&
3728 (capacity > utf8_bytes || capacity == -1)) {
3729 buffer[utf8_bytes++] = '\0';
3730 }
3731 if (nchars_ref != NULL) *nchars_ref = string_length;
3732 return utf8_bytes;
3733 }
3734 }
3735
3722 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); 3736 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3723 isolate->string_tracker()->RecordWrite(str); 3737 isolate->string_tracker()->RecordWrite(str);
3724 if (options & HINT_MANY_WRITES_EXPECTED) { 3738 if (options & HINT_MANY_WRITES_EXPECTED) {
3725 // Flatten the string for efficiency. This applies whether we are 3739 // Flatten the string for efficiency. This applies whether we are
3726 // using StringInputBuffer or Get(i) to access the characters. 3740 // using StringInputBuffer or Get(i) to access the characters.
3727 FlattenString(str); 3741 FlattenString(str);
3728 } 3742 }
3729 write_input_buffer.Reset(0, *str); 3743 write_input_buffer.Reset(0, *str);
3730 int len = str->length(); 3744 int len = str->length();
3731 // Encode the first K - 3 bytes directly into the buffer since we 3745 // Encode the first K - 3 bytes directly into the buffer since we
(...skipping 2462 matching lines...) Expand 10 before | Expand all | Expand 10 after
6194 6208
6195 6209
6196 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6210 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6197 HandleScopeImplementer* scope_implementer = 6211 HandleScopeImplementer* scope_implementer =
6198 reinterpret_cast<HandleScopeImplementer*>(storage); 6212 reinterpret_cast<HandleScopeImplementer*>(storage);
6199 scope_implementer->IterateThis(v); 6213 scope_implementer->IterateThis(v);
6200 return storage + ArchiveSpacePerThread(); 6214 return storage + ArchiveSpacePerThread();
6201 } 6215 }
6202 6216
6203 } } // namespace v8::internal 6217 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698