OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13824 Handle<String> source_; | 13824 Handle<String> source_; |
13825 Handle<SharedFunctionInfo> shared_; | 13825 Handle<SharedFunctionInfo> shared_; |
13826 StrictMode strict_mode_; | 13826 StrictMode strict_mode_; |
13827 int scope_position_; | 13827 int scope_position_; |
13828 }; | 13828 }; |
13829 | 13829 |
13830 | 13830 |
13831 // RegExpKey carries the source and flags of a regular expression as key. | 13831 // RegExpKey carries the source and flags of a regular expression as key. |
13832 class RegExpKey : public HashTableKey { | 13832 class RegExpKey : public HashTableKey { |
13833 public: | 13833 public: |
13834 RegExpKey(String* string, JSRegExp::Flags flags) | 13834 RegExpKey(Handle<String> string, JSRegExp::Flags flags) |
13835 : string_(string), | 13835 : string_(string), |
13836 flags_(Smi::FromInt(flags.value())) { } | 13836 flags_(Smi::FromInt(flags.value())) { } |
13837 | 13837 |
13838 // Rather than storing the key in the hash table, a pointer to the | 13838 // Rather than storing the key in the hash table, a pointer to the |
13839 // stored value is stored where the key should be. IsMatch then | 13839 // stored value is stored where the key should be. IsMatch then |
13840 // compares the search key to the found object, rather than comparing | 13840 // compares the search key to the found object, rather than comparing |
13841 // a key to a key. | 13841 // a key to a key. |
13842 bool IsMatch(Object* obj) { | 13842 bool IsMatch(Object* obj) { |
13843 FixedArray* val = FixedArray::cast(obj); | 13843 FixedArray* val = FixedArray::cast(obj); |
13844 return string_->Equals(String::cast(val->get(JSRegExp::kSourceIndex))) | 13844 return string_->Equals(String::cast(val->get(JSRegExp::kSourceIndex))) |
13845 && (flags_ == val->get(JSRegExp::kFlagsIndex)); | 13845 && (flags_ == val->get(JSRegExp::kFlagsIndex)); |
13846 } | 13846 } |
13847 | 13847 |
13848 uint32_t Hash() { return RegExpHash(string_, flags_); } | 13848 uint32_t Hash() { return RegExpHash(*string_, flags_); } |
13849 | 13849 |
13850 Object* AsObject(Heap* heap) { | 13850 Object* AsObject(Heap* heap) { |
13851 // Plain hash maps, which is where regexp keys are used, don't | 13851 // Plain hash maps, which is where regexp keys are used, don't |
13852 // use this function. | 13852 // use this function. |
13853 UNREACHABLE(); | 13853 UNREACHABLE(); |
13854 return NULL; | 13854 return NULL; |
13855 } | 13855 } |
13856 | 13856 |
13857 uint32_t HashForObject(Object* obj) { | 13857 uint32_t HashForObject(Object* obj) { |
13858 FixedArray* val = FixedArray::cast(obj); | 13858 FixedArray* val = FixedArray::cast(obj); |
13859 return RegExpHash(String::cast(val->get(JSRegExp::kSourceIndex)), | 13859 return RegExpHash(String::cast(val->get(JSRegExp::kSourceIndex)), |
13860 Smi::cast(val->get(JSRegExp::kFlagsIndex))); | 13860 Smi::cast(val->get(JSRegExp::kFlagsIndex))); |
13861 } | 13861 } |
13862 | 13862 |
13863 static uint32_t RegExpHash(String* string, Smi* flags) { | 13863 static uint32_t RegExpHash(String* string, Smi* flags) { |
13864 return string->Hash() + flags->value(); | 13864 return string->Hash() + flags->value(); |
13865 } | 13865 } |
13866 | 13866 |
13867 String* string_; | 13867 Handle<String> string_; |
13868 Smi* flags_; | 13868 Smi* flags_; |
13869 }; | 13869 }; |
13870 | 13870 |
13871 | 13871 |
13872 MaybeObject* OneByteStringKey::AsObject(Heap* heap) { | 13872 MaybeObject* OneByteStringKey::AsObject(Heap* heap) { |
13873 if (hash_field_ == 0) Hash(); | 13873 if (hash_field_ == 0) Hash(); |
13874 return heap->AllocateOneByteInternalizedString(string_, hash_field_); | 13874 return heap->AllocateOneByteInternalizedString(string_, hash_field_); |
13875 } | 13875 } |
13876 | 13876 |
13877 | 13877 |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15041 int entry = FindEntry(&key); | 15041 int entry = FindEntry(&key); |
15042 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 15042 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
15043 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); | 15043 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); |
15044 } | 15044 } |
15045 | 15045 |
15046 | 15046 |
15047 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, | 15047 Handle<Object> CompilationCacheTable::LookupRegExp(Handle<String> src, |
15048 JSRegExp::Flags flags) { | 15048 JSRegExp::Flags flags) { |
15049 Isolate* isolate = GetIsolate(); | 15049 Isolate* isolate = GetIsolate(); |
15050 DisallowHeapAllocation no_allocation; | 15050 DisallowHeapAllocation no_allocation; |
15051 RegExpKey key(*src, flags); | 15051 RegExpKey key(src, flags); |
15052 int entry = FindEntry(&key); | 15052 int entry = FindEntry(&key); |
15053 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 15053 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
15054 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); | 15054 return Handle<Object>(get(EntryToIndex(entry) + 1), isolate); |
15055 } | 15055 } |
15056 | 15056 |
15057 | 15057 |
15058 Handle<CompilationCacheTable> CompilationCacheTable::Put( | 15058 Handle<CompilationCacheTable> CompilationCacheTable::Put( |
15059 Handle<CompilationCacheTable> cache, Handle<String> src, | 15059 Handle<CompilationCacheTable> cache, Handle<String> src, |
15060 Handle<Context> context, Handle<Object> value) { | 15060 Handle<Context> context, Handle<Object> value) { |
15061 Isolate* isolate = cache->GetIsolate(); | 15061 Isolate* isolate = cache->GetIsolate(); |
(...skipping 23 matching lines...) Expand all Loading... |
15085 cache->set(EntryToIndex(entry), *k); | 15085 cache->set(EntryToIndex(entry), *k); |
15086 cache->set(EntryToIndex(entry) + 1, *value); | 15086 cache->set(EntryToIndex(entry) + 1, *value); |
15087 cache->ElementAdded(); | 15087 cache->ElementAdded(); |
15088 return cache; | 15088 return cache; |
15089 } | 15089 } |
15090 | 15090 |
15091 | 15091 |
15092 Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp( | 15092 Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp( |
15093 Handle<CompilationCacheTable> cache, Handle<String> src, | 15093 Handle<CompilationCacheTable> cache, Handle<String> src, |
15094 JSRegExp::Flags flags, Handle<FixedArray> value) { | 15094 JSRegExp::Flags flags, Handle<FixedArray> value) { |
15095 RegExpKey key(*src, flags); | 15095 RegExpKey key(src, flags); |
15096 cache = EnsureCapacityFor(cache, 1, &key); | 15096 cache = EnsureCapacityFor(cache, 1, &key); |
15097 int entry = cache->FindInsertionEntry(key.Hash()); | 15097 int entry = cache->FindInsertionEntry(key.Hash()); |
15098 // We store the value in the key slot, and compare the search key | 15098 // We store the value in the key slot, and compare the search key |
15099 // to the stored value with a custon IsMatch function during lookups. | 15099 // to the stored value with a custon IsMatch function during lookups. |
15100 cache->set(EntryToIndex(entry), *value); | 15100 cache->set(EntryToIndex(entry), *value); |
15101 cache->set(EntryToIndex(entry) + 1, *value); | 15101 cache->set(EntryToIndex(entry) + 1, *value); |
15102 cache->ElementAdded(); | 15102 cache->ElementAdded(); |
15103 return cache; | 15103 return cache; |
15104 } | 15104 } |
15105 | 15105 |
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16729 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16729 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16730 static const char* error_messages_[] = { | 16730 static const char* error_messages_[] = { |
16731 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16731 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16732 }; | 16732 }; |
16733 #undef ERROR_MESSAGES_TEXTS | 16733 #undef ERROR_MESSAGES_TEXTS |
16734 return error_messages_[reason]; | 16734 return error_messages_[reason]; |
16735 } | 16735 } |
16736 | 16736 |
16737 | 16737 |
16738 } } // namespace v8::internal | 16738 } } // namespace v8::internal |
OLD | NEW |