OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 17922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17933 } | 17933 } |
17934 | 17934 |
17935 | 17935 |
17936 String* StringTable::LookupKeyIfExists(Isolate* isolate, HashTableKey* key) { | 17936 String* StringTable::LookupKeyIfExists(Isolate* isolate, HashTableKey* key) { |
17937 Handle<StringTable> table = isolate->factory()->string_table(); | 17937 Handle<StringTable> table = isolate->factory()->string_table(); |
17938 int entry = table->FindEntry(key); | 17938 int entry = table->FindEntry(key); |
17939 if (entry != kNotFound) return String::cast(table->KeyAt(entry)); | 17939 if (entry != kNotFound) return String::cast(table->KeyAt(entry)); |
17940 return NULL; | 17940 return NULL; |
17941 } | 17941 } |
17942 | 17942 |
| 17943 Handle<StringSet> StringSet::New(Isolate* isolate) { |
| 17944 return HashTable::New(isolate, 0); |
| 17945 } |
| 17946 |
| 17947 Handle<StringSet> StringSet::Add(Handle<StringSet> stringset, |
| 17948 Handle<String> name) { |
| 17949 if (!stringset->Has(name)) { |
| 17950 stringset = EnsureCapacity(stringset, 1, *name); |
| 17951 uint32_t hash = StringSetShape::Hash(*name); |
| 17952 int entry = stringset->FindInsertionEntry(hash); |
| 17953 stringset->set(EntryToIndex(entry), *name); |
| 17954 stringset->ElementAdded(); |
| 17955 } |
| 17956 return stringset; |
| 17957 } |
| 17958 |
| 17959 bool StringSet::Has(Handle<String> name) { |
| 17960 return FindEntry(*name) != kNotFound; |
| 17961 } |
17943 | 17962 |
17944 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, | 17963 Handle<Object> CompilationCacheTable::Lookup(Handle<String> src, |
17945 Handle<Context> context, | 17964 Handle<Context> context, |
17946 LanguageMode language_mode) { | 17965 LanguageMode language_mode) { |
17947 Isolate* isolate = GetIsolate(); | 17966 Isolate* isolate = GetIsolate(); |
17948 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 17967 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
17949 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); | 17968 StringSharedKey key(src, shared, language_mode, RelocInfo::kNoPosition); |
17950 int entry = FindEntry(&key); | 17969 int entry = FindEntry(&key); |
17951 if (entry == kNotFound) return isolate->factory()->undefined_value(); | 17970 if (entry == kNotFound) return isolate->factory()->undefined_value(); |
17952 int index = EntryToIndex(entry); | 17971 int index = EntryToIndex(entry); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18090 if (get(value_index) == value) { | 18109 if (get(value_index) == value) { |
18091 NoWriteBarrierSet(this, entry_index, the_hole_value); | 18110 NoWriteBarrierSet(this, entry_index, the_hole_value); |
18092 NoWriteBarrierSet(this, value_index, the_hole_value); | 18111 NoWriteBarrierSet(this, value_index, the_hole_value); |
18093 ElementRemoved(); | 18112 ElementRemoved(); |
18094 } | 18113 } |
18095 } | 18114 } |
18096 return; | 18115 return; |
18097 } | 18116 } |
18098 | 18117 |
18099 | 18118 |
18100 // StringsKey used for HashTable where key is array of internalized strings. | |
18101 class StringsKey : public HashTableKey { | |
18102 public: | |
18103 explicit StringsKey(Handle<FixedArray> strings) : strings_(strings) { } | |
18104 | |
18105 bool IsMatch(Object* strings) override { | |
18106 FixedArray* o = FixedArray::cast(strings); | |
18107 int len = strings_->length(); | |
18108 if (o->length() != len) return false; | |
18109 for (int i = 0; i < len; i++) { | |
18110 if (o->get(i) != strings_->get(i)) return false; | |
18111 } | |
18112 return true; | |
18113 } | |
18114 | |
18115 uint32_t Hash() override { return HashForObject(*strings_); } | |
18116 | |
18117 uint32_t HashForObject(Object* obj) override { | |
18118 FixedArray* strings = FixedArray::cast(obj); | |
18119 int len = strings->length(); | |
18120 uint32_t hash = 0; | |
18121 for (int i = 0; i < len; i++) { | |
18122 hash ^= String::cast(strings->get(i))->Hash(); | |
18123 } | |
18124 return hash; | |
18125 } | |
18126 | |
18127 Handle<Object> AsHandle(Isolate* isolate) override { return strings_; } | |
18128 | |
18129 private: | |
18130 Handle<FixedArray> strings_; | |
18131 }; | |
18132 | |
18133 | |
18134 template<typename Derived, typename Shape, typename Key> | 18119 template<typename Derived, typename Shape, typename Key> |
18135 Handle<Derived> Dictionary<Derived, Shape, Key>::New( | 18120 Handle<Derived> Dictionary<Derived, Shape, Key>::New( |
18136 Isolate* isolate, | 18121 Isolate* isolate, |
18137 int at_least_space_for, | 18122 int at_least_space_for, |
18138 PretenureFlag pretenure) { | 18123 PretenureFlag pretenure) { |
18139 DCHECK(0 <= at_least_space_for); | 18124 DCHECK(0 <= at_least_space_for); |
18140 Handle<Derived> dict = DerivedHashTable::New(isolate, | 18125 Handle<Derived> dict = DerivedHashTable::New(isolate, |
18141 at_least_space_for, | 18126 at_least_space_for, |
18142 USE_DEFAULT_MINIMUM_CAPACITY, | 18127 USE_DEFAULT_MINIMUM_CAPACITY, |
18143 pretenure); | 18128 pretenure); |
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19769 if (cell->value() != *new_value) { | 19754 if (cell->value() != *new_value) { |
19770 cell->set_value(*new_value); | 19755 cell->set_value(*new_value); |
19771 Isolate* isolate = cell->GetIsolate(); | 19756 Isolate* isolate = cell->GetIsolate(); |
19772 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19757 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
19773 isolate, DependentCode::kPropertyCellChangedGroup); | 19758 isolate, DependentCode::kPropertyCellChangedGroup); |
19774 } | 19759 } |
19775 } | 19760 } |
19776 | 19761 |
19777 } // namespace internal | 19762 } // namespace internal |
19778 } // namespace v8 | 19763 } // namespace v8 |
OLD | NEW |