Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 2c7975bab0b90617b140cb1f00c53f14436c984f..47950ebe182955183ee106221cb862caf31bcbc4 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -2641,12 +2641,20 @@ int String::Utf8Length() const { |
} |
-int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref) const { |
+int String::WriteUtf8(char* buffer, |
+ int capacity, |
+ int* nchars_ref, |
+ WriteHints hints) const { |
if (IsDeadCheck("v8::String::WriteUtf8()")) return 0; |
LOG_API("String::WriteUtf8"); |
ENTER_V8; |
i::Handle<i::String> str = Utils::OpenHandle(this); |
StringTracker::RecordWrite(str); |
+ if (hints & 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(); |
+ } |
write_input_buffer.Reset(0, *str); |
int len = str->length(); |
// Encode the first K - 3 bytes directly into the buffer since we |
@@ -2688,16 +2696,21 @@ int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref) const { |
} |
-int String::WriteAscii(char* buffer, int start, int length) const { |
+int String::WriteAscii(char* buffer, |
+ int start, |
+ int length, |
+ WriteHints hints) const { |
if (IsDeadCheck("v8::String::WriteAscii()")) return 0; |
LOG_API("String::WriteAscii"); |
ENTER_V8; |
ASSERT(start >= 0 && length >= -1); |
i::Handle<i::String> str = Utils::OpenHandle(this); |
StringTracker::RecordWrite(str); |
- // Flatten the string for efficiency. This applies whether we are |
- // using StringInputBuffer or Get(i) to access the characters. |
- str->TryFlatten(); |
+ if (hints & 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(); |
+ } |
int end = length; |
if ( (length == -1) || (length > str->length() - start) ) |
end = str->length() - start; |
@@ -2715,13 +2728,21 @@ int String::WriteAscii(char* buffer, int start, int length) const { |
} |
-int String::Write(uint16_t* buffer, int start, int length) const { |
+int String::Write(uint16_t* buffer, |
+ int start, |
+ int length, |
+ WriteHints hints) const { |
if (IsDeadCheck("v8::String::Write()")) return 0; |
LOG_API("String::Write"); |
ENTER_V8; |
ASSERT(start >= 0 && length >= -1); |
i::Handle<i::String> str = Utils::OpenHandle(this); |
StringTracker::RecordWrite(str); |
+ if (hints & 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(); |
+ } |
int end = length; |
if ( (length == -1) || (length > str->length() - start) ) |
end = str->length() - start; |
@@ -2733,13 +2754,6 @@ int String::Write(uint16_t* buffer, int start, int length) const { |
} |
-void v8::String::Flatten() { |
- if (IsDeadCheck("v8::String::Flatten()")) return; |
- i::Handle<i::String> str = Utils::OpenHandle(this); |
- i::FlattenString(str); |
-} |
- |
- |
bool v8::String::IsExternal() const { |
EnsureInitialized("v8::String::IsExternal()"); |
i::Handle<i::String> str = Utils::OpenHandle(this); |