Push version 2.2.2 to trunk.

Introduced new profiler API.

Fixed random number generator to produce full 32 random bits.


git-svn-id: http://v8.googlecode.com/svn/trunk@4386 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/src/regexp.js b/src/regexp.js
index 9adf978..c76b09d 100644
--- a/src/regexp.js
+++ b/src/regexp.js
@@ -126,6 +126,9 @@
   this.replaceString = 0;
   this.lastIndex = 0;
   this.answer = 0;
+  // answerSaved marks whether the contents of answer is valid for a cache
+  // hit in RegExpExec, StringMatch and StringSplit.
+  this.answerSaved = false;
 }
 
 
@@ -133,6 +136,7 @@
 
 
 function CloneRegexpAnswer(array) {
+  if (array == null) return null; 
   var len = array.length;
   var answer = new $Array(len);
   for (var i = 0; i < len; i++) {
@@ -151,16 +155,16 @@
   }
 
   var cache = regExpCache;
+  var saveAnswer = false;
 
   if (%_ObjectEquals(cache.type, 'exec') &&
       %_ObjectEquals(cache.lastIndex, this.lastIndex) &&
       %_ObjectEquals(cache.regExp, this) &&
       %_ObjectEquals(cache.subject, string)) {
-    var last = cache.answer;
-    if (last == null) {
-      return last;
+    if (cache.answerSaved) {
+      return CloneRegexpAnswer(cache.answer);
     } else {
-      return CloneRegexpAnswer(last);
+      saveAnswer = true;
     }
   }
 
@@ -196,6 +200,7 @@
     cache.regExp = this;
     cache.subject = s;
     cache.answer = matchIndices;  // Null.
+    cache.answerSaved = true;     // Safe since no cloning is needed.
     cache.type = 'exec';
     return matchIndices;        // No match.
   }
@@ -225,15 +230,16 @@
   result.input = s;
   if (this.global) {
     this.lastIndex = lastMatchInfo[CAPTURE1];
-    return result;
   } else {
     cache.regExp = this;
     cache.subject = s;
     cache.lastIndex = lastIndex;
-    cache.answer = result;
+    if (saveAnswer) cache.answer = CloneRegexpAnswer(result);
+    cache.answerSaved = saveAnswer;
     cache.type = 'exec';
-    return CloneRegexpAnswer(result);
   }
+  return result;
+
 }