Revision: 4367
Author: [email protected]
Date: Thu Apr  8 11:23:10 2010
Log: Landing http://codereview.chromium.org/1594017 for Ryan.

[email protected]

Review URL: http://codereview.chromium.org/1512028
http://code.google.com/p/v8/source/detail?r=4367

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/test/cctest/test-strings.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Tue Apr  6 11:04:45 2010
+++ /branches/bleeding_edge/include/v8.h        Thu Apr  8 11:23:10 2010
@@ -865,6 +865,13 @@
                 int length = -1,
                 int* nchars_ref = NULL) const; // UTF-8

+  /**
+   * Flatten internal memory. Operations on the string tend to run faster
+   * after flattening especially if the string is a concatenation of many
+   * others.
+   */
+  void Flatten();
+
   /**
    * A zero length string.
    */
=======================================
--- /branches/bleeding_edge/src/api.cc  Thu Apr  8 06:37:39 2010
+++ /branches/bleeding_edge/src/api.cc  Thu Apr  8 11:23:10 2010
@@ -2731,6 +2731,13 @@
     buffer[end] = '\0';
   return end;
 }
+
+
+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 {
=======================================
--- /branches/bleeding_edge/test/cctest/test-strings.cc Tue Apr 6 10:58:43 2010 +++ /branches/bleeding_edge/test/cctest/test-strings.cc Thu Apr 8 11:23:10 2010
@@ -345,6 +345,38 @@
       CHECK_EQ(kNoChar, buffer[j]);
   }
 }
+
+
+TEST(StringConcatFlatten) {
+  InitializeVM();
+  v8::HandleScope handle_scope;
+
+  const char* stringA = "0123456789";
+  const char* stringB = "ABCDEFGHIJ";
+
+  v8::Local<v8::String> a = v8::String::New(stringA);
+  v8::Local<v8::String> b = v8::String::New(stringB);
+
+  v8::Local<v8::String> cons = v8::String::Concat(a, b);
+
+  i::Handle<i::String> str = v8::Utils::OpenHandle(*cons);
+  CHECK(!str->IsFlat());
+
+  cons->Flatten();
+
+  CHECK(str->IsFlat());
+
+  char buffer[21];
+  cons->WriteUtf8(buffer);
+
+  for (int i = 0; i < 10; i++) {
+    CHECK_EQ(stringA[i], buffer[i]);
+  }
+
+  for (int i = 0; i < 10; i++) {
+    CHECK_EQ(stringB[i], buffer[i + 10]);
+  }
+}


 TEST(ExternalShortStringAdd) {

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

To unsubscribe, reply using "remove me" as the subject.

Reply via email to