Revision: 9181
Author:   [email protected]
Date:     Wed Sep  7 09:15:48 2011
Log:      Fixing presubmit error.

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

Modified:
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/test/mjsunit/string-replace.js

=======================================
--- /branches/bleeding_edge/src/runtime.cc      Wed Sep  7 08:17:57 2011
+++ /branches/bleeding_edge/src/runtime.cc      Wed Sep  7 09:15:48 2011
@@ -2507,7 +2507,7 @@
 class CompiledReplacement {
  public:
   CompiledReplacement()
-      : parts_(1), replacement_substrings_(0) {}
+      : parts_(1), replacement_substrings_(0), simple_hint_(false) {}

   void Compile(Handle<String> replacement,
                int capture_count,
@@ -2522,6 +2522,10 @@
   int parts() {
     return parts_.length();
   }
+
+  bool simple_hint() {
+    return simple_hint_;
+  }

  private:
   enum PartType {
@@ -2581,15 +2585,17 @@
   };

   template<typename Char>
-  static void ParseReplacementPattern(ZoneList<ReplacementPart>* parts,
+  static bool ParseReplacementPattern(ZoneList<ReplacementPart>* parts,
                                       Vector<Char> characters,
                                       int capture_count,
                                       int subject_length) {
     int length = characters.length();
     int last = 0;
+    bool simple = true;
     for (int i = 0; i < length; i++) {
       Char c = characters[i];
       if (c == '$') {
+        simple = false;
         int next_index = i + 1;
         if (next_index == length) {  // No next character!
           break;
@@ -2682,10 +2688,12 @@
         parts->Add(ReplacementPart::ReplacementSubString(last, length));
       }
     }
+    return simple;
   }

   ZoneList<ReplacementPart> parts_;
   ZoneList<Handle<String> > replacement_substrings_;
+  bool simple_hint_;
 };


@@ -2697,16 +2705,16 @@
     String::FlatContent content = replacement->GetFlatContent();
     ASSERT(content.IsFlat());
     if (content.IsAscii()) {
-      ParseReplacementPattern(&parts_,
-                              content.ToAsciiVector(),
-                              capture_count,
-                              subject_length);
+      simple_hint_ = ParseReplacementPattern(&parts_,
+                                             content.ToAsciiVector(),
+                                             capture_count,
+                                             subject_length);
     } else {
       ASSERT(content.IsTwoByte());
-      ParseReplacementPattern(&parts_,
-                              content.ToUC16Vector(),
-                              capture_count,
-                              subject_length);
+      simple_hint_ = ParseReplacementPattern(&parts_,
+                                             content.ToUC16Vector(),
+                                             capture_count,
+                                             subject_length);
     }
   }
   Isolate* isolate = replacement->GetIsolate();
@@ -2901,7 +2909,7 @@
         isolate->factory()->NewRawTwoByteString(result_len));
   }

-  for(int i = 0; i < matches; i++) {
+  for (int i = 0; i < matches; i++) {
     // Copy non-matched subject content.
     String::WriteToFlat(*subject,
                         result->GetChars() + result_pos,
@@ -2969,7 +2977,7 @@
   // Shortcut for simple non-regexp global replacements
   if (is_global &&
       regexp->TypeTag() == JSRegExp::ATOM &&
-      compiled_replacement.parts() == 1) {
+      compiled_replacement.simple_hint()) {
     if (subject_handle->HasOnlyAsciiChars() &&
         replacement_handle->HasOnlyAsciiChars()) {
       return StringReplaceStringWithString<SeqAsciiString>(
=======================================
--- /branches/bleeding_edge/test/mjsunit/string-replace.js Tue Dec 7 03:01:02 2010 +++ /branches/bleeding_edge/test/mjsunit/string-replace.js Wed Sep 7 09:15:48 2011
@@ -207,3 +207,8 @@

 replaceTest("[ab-aabb-ab-b][az-aazz-az-z]",
             "abaz", /a(.)/g, replacer);
+
+var str = 'She sells seashells by the seashore.';
+var re = /sh/g;
+assertEquals('She sells sea$schells by the sea$schore.',
+             str.replace(re,"$$" + 'sch'))

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

Reply via email to