Do not flatten the string, but just write it out.
authorantonm@chromium.org <antonm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 30 Sep 2009 14:25:21 +0000 (14:25 +0000)
committerantonm@chromium.org <antonm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 30 Sep 2009 14:25:21 +0000 (14:25 +0000)
In DOM bindings in many cases the string would be externalized immediately.  For other cases
I am going to add explicit flattening.  Overall, it looks like if user wants to flat string
before writing, it should be an explicit method invocation (going to add TryFlattenIfNotFlat
into public V8 API).

Review URL: http://codereview.chromium.org/255004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2999 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/api.cc

index f8c8978..7c1bd60 100644 (file)
@@ -2447,20 +2447,14 @@ int String::Write(uint16_t* buffer, int start, int length) const {
   ENTER_V8;
   ASSERT(start >= 0 && length >= -1);
   i::Handle<i::String> str = Utils::OpenHandle(this);
-  // Flatten the string for efficiency.  This applies whether we are
-  // using StringInputBuffer or Get(i) to access the characters.
-  str->TryFlattenIfNotFlat();
   int end = length;
   if ( (length == -1) || (length > str->length() - start) )
     end = str->length() - start;
   if (end < 0) return 0;
-  write_input_buffer.Reset(start, *str);
-  int i;
-  for (i = 0; i < end; i++)
-    buffer[i] = write_input_buffer.GetNext();
-  if (length == -1 || i < length)
-    buffer[i] = '\0';
-  return i;
+  i::String::WriteToFlat(*str, buffer, start, end);
+  if (length == -1 || end < length)
+    buffer[end] = '\0';
+  return end;
 }