Chromium Code Reviews| Index: src/api.cc |
| diff --git a/src/api.cc b/src/api.cc |
| index ac4f07fd5e1e8e4ab9ca4b4eeaf1aa1bf9f5c728..2548c06fdd0bf6146558f3c39c899bea0b31832b 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); |
| + } |
|
Yang
2011/10/25 16:21:45
Flatten as early as possible. FlattenString does n
|
| 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,24 @@ 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()) { |
|
Yang
2011/10/25 16:21:45
Same thing as WriteUtf8. WriteToFlat is faster tha
Erik Corry
2011/10/25 19:21:22
This doesn't do the same with embedded nulls as th
|
| + int len; |
| + if (length == -1) { |
| + length = str->length() + 1; |
| + len = str->length(); |
| + } else { |
| + len = i::Min(length, str->length()); |
| + } |
| + i::String::WriteToFlat(*str, buffer, start, len); |
| + if (!(options & NO_NULL_TERMINATION) && length > len) { |
| + buffer[len] = '\0'; |
| + return len + 1; |
| + } |
| + return len; |
| + } |
| + |
| int end = length; |
| if ( (length == -1) || (length > str->length() - start) ) |
| end = str->length() - start; |
| @@ -3756,7 +3773,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) ) |