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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
===================================================================
--- src/api.cc (revision 9658)
+++ src/api.cc (working copy)
@@ -3634,13 +3634,25 @@
if (IsDeadCheck(isolate, "v8::String::WriteUtf8()")) return 0;
LOG_API(isolate, "String::WriteUtf8");
ENTER_V8(isolate);
+ i::Handle<i::String> str = Utils::OpenHandle(this);
+ if (str->IsAsciiRepresentation()) {
+ if (capacity == -1) capacity = str->length() + 1;
+ int len = i::Min(capacity, str->length());
+ i::String::WriteToFlat(*str, buffer, 0, len);
+ if (nchars_ref != NULL) *nchars_ref = len;
+ if (!(options & NO_NULL_TERMINATION) && capacity > len) {
+ buffer[len] = '\0';
+ return len + 1;
+ }
+ return len;
+ }
+
i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
- i::Handle<i::String> str = Utils::OpenHandle(this);
isolate->string_tracker()->RecordWrite(str);
if (options & HINT_MANY_WRITES_EXPECTED) {
// Flatten the string for efficiency. This applies whether we are
// using StringInputBuffer or Get(i) to access the characters.
- str->TryFlatten();
+ FlattenString(str);
}
write_input_buffer.Reset(0, *str);
int len = str->length();
« 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