Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 15078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15089 } else if (IsJSGlobalObject()) { | 15089 } else if (IsJSGlobalObject()) { |
| 15090 return global_dictionary()->CopyKeysTo(storage, index, filter, | 15090 return global_dictionary()->CopyKeysTo(storage, index, filter, |
| 15091 GlobalDictionary::UNSORTED); | 15091 GlobalDictionary::UNSORTED); |
| 15092 } else { | 15092 } else { |
| 15093 return property_dictionary()->CopyKeysTo(storage, index, filter, | 15093 return property_dictionary()->CopyKeysTo(storage, index, filter, |
| 15094 NameDictionary::UNSORTED); | 15094 NameDictionary::UNSORTED); |
| 15095 } | 15095 } |
| 15096 } | 15096 } |
| 15097 | 15097 |
| 15098 | 15098 |
| 15099 int JSObject::CollectOwnPropertyNames(KeyAccumulator* keys, | 15099 void JSObject::CollectOwnPropertyNames(KeyAccumulator* keys, |
| 15100 PropertyAttributes filter) { | 15100 PropertyAttributes filter) { |
| 15101 if (HasFastProperties()) { | 15101 if (HasFastProperties()) { |
| 15102 int nof_keys = keys->length(); | |
| 15103 int real_size = map()->NumberOfOwnDescriptors(); | 15102 int real_size = map()->NumberOfOwnDescriptors(); |
| 15104 Handle<DescriptorArray> descs(map()->instance_descriptors()); | 15103 Handle<DescriptorArray> descs(map()->instance_descriptors()); |
| 15105 for (int i = 0; i < real_size; i++) { | 15104 for (int i = 0; i < real_size; i++) { |
| 15106 if ((descs->GetDetails(i).attributes() & filter) != 0) continue; | 15105 if ((descs->GetDetails(i).attributes() & filter) != 0) continue; |
| 15107 Name* key = descs->GetKey(i); | 15106 Name* key = descs->GetKey(i); |
| 15108 if (key->FilterKey(filter)) continue; | 15107 if (key->FilterKey(filter)) continue; |
| 15109 keys->AddKey(key); | 15108 keys->AddKey(key); |
| 15110 } | 15109 } |
| 15111 return nof_keys - keys->length(); | |
| 15112 } else if (IsJSGlobalObject()) { | 15110 } else if (IsJSGlobalObject()) { |
| 15113 return global_dictionary()->CollectKeysTo(keys, filter); | 15111 global_dictionary()->CollectKeysTo(keys, filter); |
| 15114 } else { | 15112 } else { |
| 15115 return property_dictionary()->CollectKeysTo(keys, filter); | 15113 property_dictionary()->CollectKeysTo(keys, filter); |
| 15116 } | 15114 } |
| 15117 } | 15115 } |
| 15118 | 15116 |
| 15119 | 15117 |
| 15120 int JSObject::NumberOfOwnElements(PropertyAttributes filter) { | 15118 int JSObject::NumberOfOwnElements(PropertyAttributes filter) { |
| 15121 // Fast case for objects with no elements. | 15119 // Fast case for objects with no elements. |
| 15122 if (!IsJSValue() && HasFastElements()) { | 15120 if (!IsJSValue() && HasFastElements()) { |
| 15123 uint32_t length = | 15121 uint32_t length = |
| 15124 IsJSArray() | 15122 IsJSArray() |
| 15125 ? static_cast<uint32_t>( | 15123 ? static_cast<uint32_t>( |
| (...skipping 1770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16896 } | 16894 } |
| 16897 if (sort_mode == Dictionary::SORTED) { | 16895 if (sort_mode == Dictionary::SORTED) { |
| 16898 storage->SortPairs(storage, index); | 16896 storage->SortPairs(storage, index); |
| 16899 } | 16897 } |
| 16900 DCHECK(storage->length() >= index); | 16898 DCHECK(storage->length() >= index); |
| 16901 return index - start_index; | 16899 return index - start_index; |
| 16902 } | 16900 } |
| 16903 | 16901 |
| 16904 | 16902 |
| 16905 template <typename Derived, typename Shape, typename Key> | 16903 template <typename Derived, typename Shape, typename Key> |
| 16906 int Dictionary<Derived, Shape, Key>::CollectKeysTo(KeyAccumulator* keys, | 16904 void Dictionary<Derived, Shape, Key>::CollectKeysTo(KeyAccumulator* keys, |
| 16907 PropertyAttributes filter) { | 16905 PropertyAttributes filter) { |
| 16908 int capacity = this->Capacity(); | 16906 int capacity = this->Capacity(); |
| 16909 int keyLength = keys->length(); | 16907 Handle<FixedArray> array = |
| 16908 keys->isolate()->factory()->NewFixedArray(capacity); | |
|
Camillo Bruni
2015/11/17 10:02:52
I think NumberOfElements() would be better here no
| |
| 16909 int array_size = 0; | |
| 16910 | |
| 16910 for (int i = 0; i < capacity; i++) { | 16911 for (int i = 0; i < capacity; i++) { |
| 16911 Object* k = this->KeyAt(i); | 16912 Object* k = this->KeyAt(i); |
| 16912 if (!this->IsKey(k) || k->FilterKey(filter)) continue; | 16913 if (!this->IsKey(k) || k->FilterKey(filter)) continue; |
| 16913 if (this->IsDeleted(i)) continue; | 16914 if (this->IsDeleted(i)) continue; |
| 16914 PropertyDetails details = this->DetailsAt(i); | 16915 PropertyDetails details = this->DetailsAt(i); |
| 16915 PropertyAttributes attr = details.attributes(); | 16916 PropertyAttributes attr = details.attributes(); |
| 16916 if ((attr & filter) != 0) continue; | 16917 if ((attr & filter) != 0) continue; |
| 16917 keys->AddKey(k); | 16918 array->set(array_size++, Smi::FromInt(i)); |
| 16918 } | 16919 } |
| 16919 return keyLength - keys->length(); | 16920 |
| 16921 EnumIndexComparator<Derived> cmp(static_cast<Derived*>(this)); | |
| 16922 Smi** start = reinterpret_cast<Smi**>(array->GetFirstElementAddress()); | |
| 16923 std::sort(start, start + array_size, cmp); | |
| 16924 for (int i = 0; i < array_size; i++) { | |
| 16925 int index = Smi::cast(array->get(i))->value(); | |
| 16926 keys->AddKey(this->KeyAt(index)); | |
| 16927 } | |
| 16920 } | 16928 } |
| 16921 | 16929 |
| 16922 | 16930 |
| 16923 // Backwards lookup (slow). | 16931 // Backwards lookup (slow). |
| 16924 template<typename Derived, typename Shape, typename Key> | 16932 template<typename Derived, typename Shape, typename Key> |
| 16925 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) { | 16933 Object* Dictionary<Derived, Shape, Key>::SlowReverseLookup(Object* value) { |
| 16926 int capacity = this->Capacity(); | 16934 int capacity = this->Capacity(); |
| 16927 for (int i = 0; i < capacity; i++) { | 16935 for (int i = 0; i < capacity; i++) { |
| 16928 Object* k = this->KeyAt(i); | 16936 Object* k = this->KeyAt(i); |
| 16929 if (this->IsKey(k)) { | 16937 if (this->IsKey(k)) { |
| (...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 18122 if (cell->value() != *new_value) { | 18130 if (cell->value() != *new_value) { |
| 18123 cell->set_value(*new_value); | 18131 cell->set_value(*new_value); |
| 18124 Isolate* isolate = cell->GetIsolate(); | 18132 Isolate* isolate = cell->GetIsolate(); |
| 18125 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18133 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 18126 isolate, DependentCode::kPropertyCellChangedGroup); | 18134 isolate, DependentCode::kPropertyCellChangedGroup); |
| 18127 } | 18135 } |
| 18128 } | 18136 } |
| 18129 | 18137 |
| 18130 } // namespace internal | 18138 } // namespace internal |
| 18131 } // namespace v8 | 18139 } // namespace v8 |
| OLD | NEW |