Index: src/heap.cc |
diff --git a/src/heap.cc b/src/heap.cc |
index 8fc025338625aaed00cee4c5101c799296a24d84..88a9cb30466248e16d4a4158aa7eda91fea8c3aa 100644 |
--- a/src/heap.cc |
+++ b/src/heap.cc |
@@ -1002,7 +1002,8 @@ void Heap::MarkCompactPrologue() { |
isolate_->keyed_lookup_cache()->Clear(); |
isolate_->context_slot_cache()->Clear(); |
isolate_->descriptor_lookup_cache()->Clear(); |
- StringSplitCache::Clear(string_split_cache()); |
+ RegExpResultsCache::Clear(string_split_cache()); |
+ RegExpResultsCache::Clear(regexp_multiple_cache()); |
isolate_->compilation_cache()->MarkCompactPrologue(); |
@@ -2757,12 +2758,18 @@ bool Heap::CreateInitialObjects() { |
set_single_character_string_cache(FixedArray::cast(obj)); |
// Allocate cache for string split. |
- { MaybeObject* maybe_obj = |
- AllocateFixedArray(StringSplitCache::kStringSplitCacheSize, TENURED); |
+ { MaybeObject* maybe_obj = AllocateFixedArray( |
+ RegExpResultsCache::kRegExpResultsCacheSize, TENURED); |
if (!maybe_obj->ToObject(&obj)) return false; |
} |
set_string_split_cache(FixedArray::cast(obj)); |
+ { MaybeObject* maybe_obj = AllocateFixedArray( |
+ RegExpResultsCache::kRegExpResultsCacheSize, TENURED); |
+ if (!maybe_obj->ToObject(&obj)) return false; |
+ } |
+ set_regexp_multiple_cache(FixedArray::cast(obj)); |
+ |
// Allocate cache for external strings pointing to native source code. |
{ MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount()); |
if (!maybe_obj->ToObject(&obj)) return false; |
@@ -2788,17 +2795,20 @@ bool Heap::CreateInitialObjects() { |
} |
-Object* StringSplitCache::Lookup( |
- FixedArray* cache, String* string, String* pattern) { |
- if (!string->IsSymbol() || !pattern->IsSymbol()) return Smi::FromInt(0); |
+Object* RegExpResultsCache::Lookup( |
+ FixedArray* cache, String* string, Object* pattern) { |
+ if (!string->IsSymbol() || (pattern->IsString() && !pattern->IsSymbol())) { |
+ return Smi::FromInt(0); |
+ } |
uint32_t hash = string->Hash(); |
- uint32_t index = ((hash & (kStringSplitCacheSize - 1)) & |
+ uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
~(kArrayEntriesPerCacheEntry - 1)); |
if (cache->get(index + kStringOffset) == string && |
cache->get(index + kPatternOffset) == pattern) { |
return cache->get(index + kArrayOffset); |
} |
- index = ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1)); |
+ index = |
+ ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
if (cache->get(index + kStringOffset) == string && |
cache->get(index + kPatternOffset) == pattern) { |
return cache->get(index + kArrayOffset); |
@@ -2807,14 +2817,16 @@ Object* StringSplitCache::Lookup( |
} |
-void StringSplitCache::Enter(Heap* heap, |
+void RegExpResultsCache::Enter(Heap* heap, |
FixedArray* cache, |
String* string, |
- String* pattern, |
+ Object* pattern, |
FixedArray* array) { |
- if (!string->IsSymbol() || !pattern->IsSymbol()) return; |
+ if (!string->IsSymbol() || (pattern->IsString() && !pattern->IsSymbol())) { |
+ return; |
+ } |
uint32_t hash = string->Hash(); |
- uint32_t index = ((hash & (kStringSplitCacheSize - 1)) & |
+ uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
~(kArrayEntriesPerCacheEntry - 1)); |
if (cache->get(index + kStringOffset) == Smi::FromInt(0)) { |
cache->set(index + kStringOffset, string); |
@@ -2822,7 +2834,7 @@ void StringSplitCache::Enter(Heap* heap, |
cache->set(index + kArrayOffset, array); |
} else { |
uint32_t index2 = |
- ((index + kArrayEntriesPerCacheEntry) & (kStringSplitCacheSize - 1)); |
+ ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) { |
cache->set(index2 + kStringOffset, string); |
cache->set(index2 + kPatternOffset, pattern); |
@@ -2836,7 +2848,9 @@ void StringSplitCache::Enter(Heap* heap, |
cache->set(index + kArrayOffset, array); |
} |
} |
- if (array->length() < 100) { // Limit how many new symbols we want to make. |
+ if (pattern->IsString() && array->length() < 100) { |
+ // Limit how many new symbols we want to make, when used on a list only |
+ // consisting of strings. |
for (int i = 0; i < array->length(); i++) { |
String* str = String::cast(array->get(i)); |
Object* symbol; |
@@ -2850,8 +2864,8 @@ void StringSplitCache::Enter(Heap* heap, |
} |
-void StringSplitCache::Clear(FixedArray* cache) { |
- for (int i = 0; i < kStringSplitCacheSize; i++) { |
+void RegExpResultsCache::Clear(FixedArray* cache) { |
+ for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
cache->set(i, Smi::FromInt(0)); |
} |
} |