Reviewers: Erik Corry,
Message:
Please take a look.
http://codereview.chromium.org/8390004/diff/1/src/api.cc
File src/api.cc (right):
http://codereview.chromium.org/8390004/diff/1/src/api.cc#newcode3649
src/api.cc:3649: }
Flatten as early as possible. FlattenString does nothing else than
WriteToFlat. This way, the WriteToFlat in the Ascii case will be merely
a copy from the already flattened string.
http://codereview.chromium.org/8390004/diff/1/src/api.cc#newcode3729
src/api.cc:3729: if (str->IsAsciiRepresentation()) {
Same thing as WriteUtf8. WriteToFlat is faster than
InputBuffer/ReadBlock because in case of a convoluted cons string,
ReadBlock has to hunt down the right part to read from after every 1024
characters (buffer size).
Description:
Improve WriteUtf8 and WriteAscii.
Please review this at http://codereview.chromium.org/8390004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/api.cc
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);
+ }
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()) {
+ 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) )
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev