| Index: src/api.cc
|
| diff --git a/src/api.cc b/src/api.cc
|
| index ac4f07fd5e1e8e4ab9ca4b4eeaf1aa1bf9f5c728..5c6b6e8a0f36b767ed364d98d5989764acca98c2 100644
|
| --- a/src/api.cc
|
| +++ b/src/api.cc
|
| @@ -3642,6 +3642,11 @@ int String::WriteUtf8(char* buffer,
|
| LOG_API(isolate, "String::WriteUtf8");
|
| ENTER_V8(isolate);
|
| i::Handle<i::String> str = Utils::OpenHandle(this);
|
| + 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.
|
| + FlattenString(str);
|
| + }
|
| if (str->IsAsciiRepresentation()) {
|
| int len;
|
| if (capacity == -1) {
|
| @@ -3661,11 +3666,7 @@ int String::WriteUtf8(char* buffer,
|
|
|
| i::StringInputBuffer& write_input_buffer = *isolate->write_input_buffer();
|
| 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.
|
| - FlattenString(str);
|
| - }
|
| +
|
| write_input_buffer.Reset(0, *str);
|
| int len = str->length();
|
| // Encode the first K - 3 bytes directly into the buffer since we
|
| @@ -3723,8 +3724,21 @@ int String::WriteAscii(char* buffer,
|
| 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);
|
| + }
|
| + if (str->IsAsciiRepresentation()) {
|
| + if (length == -1) length = str->length() + 1;
|
| + int len = i::Min(length, str->length() - start);
|
| + i::String::WriteToFlat(*str, buffer, start, start + len);
|
| + for (int i = 0; i < len; i++) {
|
| + if (buffer[i] == '\0') buffer[i] = ' ';
|
| + }
|
| + if (!(options & NO_NULL_TERMINATION) && length > len) {
|
| + buffer[len] = '\0';
|
| + }
|
| + return len;
|
| }
|
| +
|
| int end = length;
|
| if ( (length == -1) || (length > str->length() - start) )
|
| end = str->length() - start;
|
| @@ -3756,7 +3770,7 @@ int String::Write(uint16_t* buffer,
|
| 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);
|
| }
|
| int end = start + length;
|
| if ((length == -1) || (length > str->length() - start) )
|
|
|