Fix one off error.
authorantonm@chromium.org <antonm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 21 Apr 2010 11:13:53 +0000 (11:13 +0000)
committerantonm@chromium.org <antonm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 21 Apr 2010 11:13:53 +0000 (11:13 +0000)
Proper condition to start eviction is when next possible index is equal
to cache length.

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

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

src/objects.h
src/runtime.cc
test/mjsunit/string-search.js

index 1639457..cdc2491 100644 (file)
@@ -2322,6 +2322,8 @@ class JSFunctionResultCache: public FixedArray {
   static const int kCacheSizeIndex = kFingerIndex + 1;
   static const int kDummyIndex = kCacheSizeIndex + 1;
   static const int kEntriesIndex = kDummyIndex + 1;
+
+  static const int kEntrySize = 2;  // key + value
 };
 
 
index 5e43129..ab77018 100644 (file)
@@ -10101,8 +10101,10 @@ static Object* Runtime_GetFromCache(Arguments args) {
     cache->set(JSFunctionResultCache::kCacheSizeIndex, Smi::FromInt(size + 2));
     return CacheMiss(cache, size, key);
   } else {
-    int target_index = (finger_index < cache->length()) ?
-        finger_index + 2 : JSFunctionResultCache::kEntriesIndex;
+    int target_index = finger_index + JSFunctionResultCache::kEntrySize;
+    if (target_index == cache->length()) {
+      target_index = JSFunctionResultCache::kEntriesIndex;
+    }
     return CacheMiss(cache, target_index, key);
   }
 }
index 36891c2..4de17bc 100644 (file)
 var str="ABC abc";
 var r = str.search('a');
 assertEquals(r, 4);
+
+// Test for a lot of different string.
+
+var s = "";
+for (var i = 0; i < 100; i++) {
+  s += i;
+  var r = s.search(s);
+  assertEquals(0, r);
+}
+