OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/regexp/jsregexp.h" | 5 #include "src/regexp/jsregexp.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 410 } |
411 | 411 |
412 | 412 |
413 void RegExpImpl::SetIrregexpMaxRegisterCount(FixedArray* re, int value) { | 413 void RegExpImpl::SetIrregexpMaxRegisterCount(FixedArray* re, int value) { |
414 re->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(value)); | 414 re->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(value)); |
415 } | 415 } |
416 | 416 |
417 void RegExpImpl::SetIrregexpCaptureNameMap(FixedArray* re, | 417 void RegExpImpl::SetIrregexpCaptureNameMap(FixedArray* re, |
418 Handle<FixedArray> value) { | 418 Handle<FixedArray> value) { |
419 if (value.is_null()) { | 419 if (value.is_null()) { |
420 re->set(JSRegExp::kIrregexpCaptureNameMapIndex, Smi::kZero); | 420 re->set(JSRegExp::kIrregexpCaptureNameMapIndex, Smi::FromInt(0)); |
421 } else { | 421 } else { |
422 re->set(JSRegExp::kIrregexpCaptureNameMapIndex, *value); | 422 re->set(JSRegExp::kIrregexpCaptureNameMapIndex, *value); |
423 } | 423 } |
424 } | 424 } |
425 | 425 |
426 int RegExpImpl::IrregexpNumberOfCaptures(FixedArray* re) { | 426 int RegExpImpl::IrregexpNumberOfCaptures(FixedArray* re) { |
427 return Smi::cast(re->get(JSRegExp::kIrregexpCaptureCountIndex))->value(); | 427 return Smi::cast(re->get(JSRegExp::kIrregexpCaptureCountIndex))->value(); |
428 } | 428 } |
429 | 429 |
430 | 430 |
(...skipping 6343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6774 } | 6774 } |
6775 return too_much; | 6775 return too_much; |
6776 } | 6776 } |
6777 | 6777 |
6778 | 6778 |
6779 Object* RegExpResultsCache::Lookup(Heap* heap, String* key_string, | 6779 Object* RegExpResultsCache::Lookup(Heap* heap, String* key_string, |
6780 Object* key_pattern, | 6780 Object* key_pattern, |
6781 FixedArray** last_match_cache, | 6781 FixedArray** last_match_cache, |
6782 ResultsCacheType type) { | 6782 ResultsCacheType type) { |
6783 FixedArray* cache; | 6783 FixedArray* cache; |
6784 if (!key_string->IsInternalizedString()) return Smi::kZero; | 6784 if (!key_string->IsInternalizedString()) return Smi::FromInt(0); |
6785 if (type == STRING_SPLIT_SUBSTRINGS) { | 6785 if (type == STRING_SPLIT_SUBSTRINGS) { |
6786 DCHECK(key_pattern->IsString()); | 6786 DCHECK(key_pattern->IsString()); |
6787 if (!key_pattern->IsInternalizedString()) return Smi::kZero; | 6787 if (!key_pattern->IsInternalizedString()) return Smi::FromInt(0); |
6788 cache = heap->string_split_cache(); | 6788 cache = heap->string_split_cache(); |
6789 } else { | 6789 } else { |
6790 DCHECK(type == REGEXP_MULTIPLE_INDICES); | 6790 DCHECK(type == REGEXP_MULTIPLE_INDICES); |
6791 DCHECK(key_pattern->IsFixedArray()); | 6791 DCHECK(key_pattern->IsFixedArray()); |
6792 cache = heap->regexp_multiple_cache(); | 6792 cache = heap->regexp_multiple_cache(); |
6793 } | 6793 } |
6794 | 6794 |
6795 uint32_t hash = key_string->Hash(); | 6795 uint32_t hash = key_string->Hash(); |
6796 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & | 6796 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
6797 ~(kArrayEntriesPerCacheEntry - 1)); | 6797 ~(kArrayEntriesPerCacheEntry - 1)); |
6798 if (cache->get(index + kStringOffset) != key_string || | 6798 if (cache->get(index + kStringOffset) != key_string || |
6799 cache->get(index + kPatternOffset) != key_pattern) { | 6799 cache->get(index + kPatternOffset) != key_pattern) { |
6800 index = | 6800 index = |
6801 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); | 6801 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
6802 if (cache->get(index + kStringOffset) != key_string || | 6802 if (cache->get(index + kStringOffset) != key_string || |
6803 cache->get(index + kPatternOffset) != key_pattern) { | 6803 cache->get(index + kPatternOffset) != key_pattern) { |
6804 return Smi::kZero; | 6804 return Smi::FromInt(0); |
6805 } | 6805 } |
6806 } | 6806 } |
6807 | 6807 |
6808 *last_match_cache = FixedArray::cast(cache->get(index + kLastMatchOffset)); | 6808 *last_match_cache = FixedArray::cast(cache->get(index + kLastMatchOffset)); |
6809 return cache->get(index + kArrayOffset); | 6809 return cache->get(index + kArrayOffset); |
6810 } | 6810 } |
6811 | 6811 |
6812 | 6812 |
6813 void RegExpResultsCache::Enter(Isolate* isolate, Handle<String> key_string, | 6813 void RegExpResultsCache::Enter(Isolate* isolate, Handle<String> key_string, |
6814 Handle<Object> key_pattern, | 6814 Handle<Object> key_pattern, |
6815 Handle<FixedArray> value_array, | 6815 Handle<FixedArray> value_array, |
6816 Handle<FixedArray> last_match_cache, | 6816 Handle<FixedArray> last_match_cache, |
6817 ResultsCacheType type) { | 6817 ResultsCacheType type) { |
6818 Factory* factory = isolate->factory(); | 6818 Factory* factory = isolate->factory(); |
6819 Handle<FixedArray> cache; | 6819 Handle<FixedArray> cache; |
6820 if (!key_string->IsInternalizedString()) return; | 6820 if (!key_string->IsInternalizedString()) return; |
6821 if (type == STRING_SPLIT_SUBSTRINGS) { | 6821 if (type == STRING_SPLIT_SUBSTRINGS) { |
6822 DCHECK(key_pattern->IsString()); | 6822 DCHECK(key_pattern->IsString()); |
6823 if (!key_pattern->IsInternalizedString()) return; | 6823 if (!key_pattern->IsInternalizedString()) return; |
6824 cache = factory->string_split_cache(); | 6824 cache = factory->string_split_cache(); |
6825 } else { | 6825 } else { |
6826 DCHECK(type == REGEXP_MULTIPLE_INDICES); | 6826 DCHECK(type == REGEXP_MULTIPLE_INDICES); |
6827 DCHECK(key_pattern->IsFixedArray()); | 6827 DCHECK(key_pattern->IsFixedArray()); |
6828 cache = factory->regexp_multiple_cache(); | 6828 cache = factory->regexp_multiple_cache(); |
6829 } | 6829 } |
6830 | 6830 |
6831 uint32_t hash = key_string->Hash(); | 6831 uint32_t hash = key_string->Hash(); |
6832 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & | 6832 uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & |
6833 ~(kArrayEntriesPerCacheEntry - 1)); | 6833 ~(kArrayEntriesPerCacheEntry - 1)); |
6834 if (cache->get(index + kStringOffset) == Smi::kZero) { | 6834 if (cache->get(index + kStringOffset) == Smi::FromInt(0)) { |
6835 cache->set(index + kStringOffset, *key_string); | 6835 cache->set(index + kStringOffset, *key_string); |
6836 cache->set(index + kPatternOffset, *key_pattern); | 6836 cache->set(index + kPatternOffset, *key_pattern); |
6837 cache->set(index + kArrayOffset, *value_array); | 6837 cache->set(index + kArrayOffset, *value_array); |
6838 cache->set(index + kLastMatchOffset, *last_match_cache); | 6838 cache->set(index + kLastMatchOffset, *last_match_cache); |
6839 } else { | 6839 } else { |
6840 uint32_t index2 = | 6840 uint32_t index2 = |
6841 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); | 6841 ((index + kArrayEntriesPerCacheEntry) & (kRegExpResultsCacheSize - 1)); |
6842 if (cache->get(index2 + kStringOffset) == Smi::kZero) { | 6842 if (cache->get(index2 + kStringOffset) == Smi::FromInt(0)) { |
6843 cache->set(index2 + kStringOffset, *key_string); | 6843 cache->set(index2 + kStringOffset, *key_string); |
6844 cache->set(index2 + kPatternOffset, *key_pattern); | 6844 cache->set(index2 + kPatternOffset, *key_pattern); |
6845 cache->set(index2 + kArrayOffset, *value_array); | 6845 cache->set(index2 + kArrayOffset, *value_array); |
6846 cache->set(index2 + kLastMatchOffset, *last_match_cache); | 6846 cache->set(index2 + kLastMatchOffset, *last_match_cache); |
6847 } else { | 6847 } else { |
6848 cache->set(index2 + kStringOffset, Smi::kZero); | 6848 cache->set(index2 + kStringOffset, Smi::FromInt(0)); |
6849 cache->set(index2 + kPatternOffset, Smi::kZero); | 6849 cache->set(index2 + kPatternOffset, Smi::FromInt(0)); |
6850 cache->set(index2 + kArrayOffset, Smi::kZero); | 6850 cache->set(index2 + kArrayOffset, Smi::FromInt(0)); |
6851 cache->set(index2 + kLastMatchOffset, Smi::kZero); | 6851 cache->set(index2 + kLastMatchOffset, Smi::FromInt(0)); |
6852 cache->set(index + kStringOffset, *key_string); | 6852 cache->set(index + kStringOffset, *key_string); |
6853 cache->set(index + kPatternOffset, *key_pattern); | 6853 cache->set(index + kPatternOffset, *key_pattern); |
6854 cache->set(index + kArrayOffset, *value_array); | 6854 cache->set(index + kArrayOffset, *value_array); |
6855 cache->set(index + kLastMatchOffset, *last_match_cache); | 6855 cache->set(index + kLastMatchOffset, *last_match_cache); |
6856 } | 6856 } |
6857 } | 6857 } |
6858 // If the array is a reasonably short list of substrings, convert it into a | 6858 // If the array is a reasonably short list of substrings, convert it into a |
6859 // list of internalized strings. | 6859 // list of internalized strings. |
6860 if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) { | 6860 if (type == STRING_SPLIT_SUBSTRINGS && value_array->length() < 100) { |
6861 for (int i = 0; i < value_array->length(); i++) { | 6861 for (int i = 0; i < value_array->length(); i++) { |
6862 Handle<String> str(String::cast(value_array->get(i)), isolate); | 6862 Handle<String> str(String::cast(value_array->get(i)), isolate); |
6863 Handle<String> internalized_str = factory->InternalizeString(str); | 6863 Handle<String> internalized_str = factory->InternalizeString(str); |
6864 value_array->set(i, *internalized_str); | 6864 value_array->set(i, *internalized_str); |
6865 } | 6865 } |
6866 } | 6866 } |
6867 // Convert backing store to a copy-on-write array. | 6867 // Convert backing store to a copy-on-write array. |
6868 value_array->set_map_no_write_barrier(*factory->fixed_cow_array_map()); | 6868 value_array->set_map_no_write_barrier(*factory->fixed_cow_array_map()); |
6869 } | 6869 } |
6870 | 6870 |
6871 | 6871 |
6872 void RegExpResultsCache::Clear(FixedArray* cache) { | 6872 void RegExpResultsCache::Clear(FixedArray* cache) { |
6873 for (int i = 0; i < kRegExpResultsCacheSize; i++) { | 6873 for (int i = 0; i < kRegExpResultsCacheSize; i++) { |
6874 cache->set(i, Smi::kZero); | 6874 cache->set(i, Smi::FromInt(0)); |
6875 } | 6875 } |
6876 } | 6876 } |
6877 | 6877 |
6878 } // namespace internal | 6878 } // namespace internal |
6879 } // namespace v8 | 6879 } // namespace v8 |
OLD | NEW |