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

Side by Side Diff: src/api.cc

Issue 8304021: Improve speed of Utf8Write by always flattening the string first and (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 2 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') | 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 3616 matching lines...) Expand 10 before | Expand all | Expand 10 after
3627 3627
3628 3628
3629 int String::WriteUtf8(char* buffer, 3629 int String::WriteUtf8(char* buffer,
3630 int capacity, 3630 int capacity,
3631 int* nchars_ref, 3631 int* nchars_ref,
3632 int options) const { 3632 int options) const {
3633 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3633 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3634 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0; 3634 if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
3635 LOG_API(isolate, "String::WriteUtf8"); 3635 LOG_API(isolate, "String::WriteUtf8");
3636 ENTER_V8(isolate); 3636 ENTER_V8(isolate);
3637 i::Handle<i::String> str = Utils::OpenHandle(this);
3638 if (str->IsAsciiRepresentation()) {
3639 if (capacity == -1) capacity = str->length() + 1;
3640 int len = i::Min(capacity, str->length());
3641 i::String::WriteToFlat(*str, buffer, 0, len);
3642 if (nchars_ref != NULL) *nchars_ref = len;
3643 if (!(options & NO_NULL_TERMINATION) && capacity > len) {
3644 buffer[len] = '\0';
3645 return len + 1;
3646 }
3647 return len;
3648 }
3649
3637 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer(); 3650 i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
3638 i::Handle<i::String> str = Utils::OpenHandle(this);
3639 isolate->string_tracker()->RecordWrite(str); 3651 isolate->string_tracker()->RecordWrite(str);
3640 if (options & HINT_MANY_WRITES_EXPECTED) { 3652 if (options & HINT_MANY_WRITES_EXPECTED) {
3641 // Flatten the string for efficiency. This applies whether we are 3653 // Flatten the string for efficiency. This applies whether we are
3642 // using StringInputBuffer or Get(i) to access the characters. 3654 // using StringInputBuffer or Get(i) to access the characters.
3643 str->TryFlatten(); 3655 FlattenString(str);
3644 } 3656 }
3645 write_input_buffer.Reset(0, *str); 3657 write_input_buffer.Reset(0, *str);
3646 int len = str->length(); 3658 int len = str->length();
3647 // Encode the first K - 3 bytes directly into the buffer since we 3659 // Encode the first K - 3 bytes directly into the buffer since we
3648 // know there's room for them. If no capacity is given we copy all 3660 // know there's room for them. If no capacity is given we copy all
3649 // of them here. 3661 // of them here.
3650 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1); 3662 int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1);
3651 int i; 3663 int i;
3652 int pos = 0; 3664 int pos = 0;
3653 int nchars = 0; 3665 int nchars = 0;
(...skipping 2420 matching lines...) Expand 10 before | Expand all | Expand 10 after
6074 6086
6075 6087
6076 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 6088 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
6077 HandleScopeImplementer* scope_implementer = 6089 HandleScopeImplementer* scope_implementer =
6078 reinterpret_cast<HandleScopeImplementer*>(storage); 6090 reinterpret_cast<HandleScopeImplementer*>(storage);
6079 scope_implementer->IterateThis(v); 6091 scope_implementer->IterateThis(v);
6080 return storage + ArchiveSpacePerThread(); 6092 return storage + ArchiveSpacePerThread();
6081 } 6093 }
6082 6094
6083 } } // namespace v8::internal 6095 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698