| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 6830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6841 Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity)); | 6841 Object* obj = Heap::AllocateHashTable(EntryToIndex(capacity)); |
| 6842 if (!obj->IsFailure()) { | 6842 if (!obj->IsFailure()) { |
| 6843 HashTable::cast(obj)->SetNumberOfElements(0); | 6843 HashTable::cast(obj)->SetNumberOfElements(0); |
| 6844 HashTable::cast(obj)->SetNumberOfDeletedElements(0); | 6844 HashTable::cast(obj)->SetNumberOfDeletedElements(0); |
| 6845 HashTable::cast(obj)->SetCapacity(capacity); | 6845 HashTable::cast(obj)->SetCapacity(capacity); |
| 6846 } | 6846 } |
| 6847 return obj; | 6847 return obj; |
| 6848 } | 6848 } |
| 6849 | 6849 |
| 6850 | 6850 |
| 6851 | 6851 // Find entry for key otherwise return kNotFound. |
| 6852 // Find entry for key otherwise return -1. | |
| 6853 template<typename Shape, typename Key> | 6852 template<typename Shape, typename Key> |
| 6854 int HashTable<Shape, Key>::FindEntry(Key key) { | 6853 int HashTable<Shape, Key>::FindEntry(Key key) { |
| 6855 uint32_t nof = NumberOfElements(); | |
| 6856 if (nof == 0) return kNotFound; // Bail out if empty. | |
| 6857 | |
| 6858 uint32_t capacity = Capacity(); | 6854 uint32_t capacity = Capacity(); |
| 6859 uint32_t hash = Shape::Hash(key); | 6855 uint32_t entry = FirstProbe(Shape::Hash(key), capacity); |
| 6860 uint32_t entry = GetProbe(hash, 0, capacity); | 6856 uint32_t count = 1; |
| 6861 | 6857 // EnsureCapacity will guarantee the hash table is never full. |
| 6862 Object* element = KeyAt(entry); | 6858 while (true) { |
| 6863 uint32_t passed_elements = 0; | 6859 Object* element = KeyAt(entry); |
| 6864 if (!element->IsNull()) { | 6860 if (element->IsUndefined()) break; // Empty entry. |
| 6865 if (!element->IsUndefined() && Shape::IsMatch(key, element)) return entry; | 6861 if (!element->IsNull() && Shape::IsMatch(key, element)) return entry; |
| 6866 if (++passed_elements == nof) return kNotFound; | 6862 entry = NextProbe(entry, count++, capacity); |
| 6867 } | |
| 6868 for (uint32_t i = 1; !element->IsUndefined(); i++) { | |
| 6869 entry = GetProbe(hash, i, capacity); | |
| 6870 element = KeyAt(entry); | |
| 6871 if (!element->IsNull()) { | |
| 6872 if (!element->IsUndefined() && Shape::IsMatch(key, element)) return entry; | |
| 6873 if (++passed_elements == nof) return kNotFound; | |
| 6874 } | |
| 6875 } | 6863 } |
| 6876 return kNotFound; | 6864 return kNotFound; |
| 6877 } | 6865 } |
| 6878 | 6866 |
| 6879 | 6867 |
| 6880 template<typename Shape, typename Key> | 6868 template<typename Shape, typename Key> |
| 6881 Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { | 6869 Object* HashTable<Shape, Key>::EnsureCapacity(int n, Key key) { |
| 6882 int capacity = Capacity(); | 6870 int capacity = Capacity(); |
| 6883 int nof = NumberOfElements() + n; | 6871 int nof = NumberOfElements() + n; |
| 6884 int nod = NumberOfDeletedElements(); | 6872 int nod = NumberOfDeletedElements(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 6911 table->set(insertion_index + j, get(from_index + j), mode); | 6899 table->set(insertion_index + j, get(from_index + j), mode); |
| 6912 } | 6900 } |
| 6913 } | 6901 } |
| 6914 } | 6902 } |
| 6915 table->SetNumberOfElements(NumberOfElements()); | 6903 table->SetNumberOfElements(NumberOfElements()); |
| 6916 table->SetNumberOfDeletedElements(0); | 6904 table->SetNumberOfDeletedElements(0); |
| 6917 return table; | 6905 return table; |
| 6918 } | 6906 } |
| 6919 | 6907 |
| 6920 | 6908 |
| 6909 |
| 6921 template<typename Shape, typename Key> | 6910 template<typename Shape, typename Key> |
| 6922 uint32_t HashTable<Shape, Key>::FindInsertionEntry(uint32_t hash) { | 6911 uint32_t HashTable<Shape, Key>::FindInsertionEntry(uint32_t hash) { |
| 6923 uint32_t capacity = Capacity(); | 6912 uint32_t capacity = Capacity(); |
| 6924 uint32_t entry = GetProbe(hash, 0, capacity); | 6913 uint32_t entry = FirstProbe(hash, capacity); |
| 6925 Object* element = KeyAt(entry); | 6914 uint32_t count = 1; |
| 6926 | 6915 // EnsureCapacity will guarantee the hash table is never full. |
| 6927 for (uint32_t i = 1; !(element->IsUndefined() || element->IsNull()); i++) { | 6916 while (true) { |
| 6928 entry = GetProbe(hash, i, capacity); | 6917 Object* element = KeyAt(entry); |
| 6929 element = KeyAt(entry); | 6918 if (element->IsUndefined() || element->IsNull()) break; |
| 6919 entry = NextProbe(entry, count++, capacity); |
| 6930 } | 6920 } |
| 6931 | |
| 6932 return entry; | 6921 return entry; |
| 6933 } | 6922 } |
| 6934 | 6923 |
| 6935 // Force instantiation of template instances class. | 6924 // Force instantiation of template instances class. |
| 6936 // Please note this list is compiler dependent. | 6925 // Please note this list is compiler dependent. |
| 6937 | 6926 |
| 6938 template class HashTable<SymbolTableShape, HashTableKey*>; | 6927 template class HashTable<SymbolTableShape, HashTableKey*>; |
| 6939 | 6928 |
| 6940 template class HashTable<CompilationCacheShape, HashTableKey*>; | 6929 template class HashTable<CompilationCacheShape, HashTableKey*>; |
| 6941 | 6930 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7000 | 6989 |
| 7001 template Object* Dictionary<StringDictionaryShape, String*>::AddEntry( | 6990 template Object* Dictionary<StringDictionaryShape, String*>::AddEntry( |
| 7002 String*, Object*, PropertyDetails, uint32_t); | 6991 String*, Object*, PropertyDetails, uint32_t); |
| 7003 | 6992 |
| 7004 template | 6993 template |
| 7005 int Dictionary<NumberDictionaryShape, uint32_t>::NumberOfEnumElements(); | 6994 int Dictionary<NumberDictionaryShape, uint32_t>::NumberOfEnumElements(); |
| 7006 | 6995 |
| 7007 template | 6996 template |
| 7008 int Dictionary<StringDictionaryShape, String*>::NumberOfEnumElements(); | 6997 int Dictionary<StringDictionaryShape, String*>::NumberOfEnumElements(); |
| 7009 | 6998 |
| 6999 template |
| 7000 int HashTable<NumberDictionaryShape, uint32_t>::FindEntry(uint32_t); |
| 7001 |
| 7002 |
| 7010 // Collates undefined and unexisting elements below limit from position | 7003 // Collates undefined and unexisting elements below limit from position |
| 7011 // zero of the elements. The object stays in Dictionary mode. | 7004 // zero of the elements. The object stays in Dictionary mode. |
| 7012 Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) { | 7005 Object* JSObject::PrepareSlowElementsForSort(uint32_t limit) { |
| 7013 ASSERT(HasDictionaryElements()); | 7006 ASSERT(HasDictionaryElements()); |
| 7014 // Must stay in dictionary mode, either because of requires_slow_elements, | 7007 // Must stay in dictionary mode, either because of requires_slow_elements, |
| 7015 // or because we are not going to sort (and therefore compact) all of the | 7008 // or because we are not going to sort (and therefore compact) all of the |
| 7016 // elements. | 7009 // elements. |
| 7017 NumberDictionary* dict = element_dictionary(); | 7010 NumberDictionary* dict = element_dictionary(); |
| 7018 HeapNumber* result_double = NULL; | 7011 HeapNumber* result_double = NULL; |
| 7019 if (limit > static_cast<uint32_t>(Smi::kMaxValue)) { | 7012 if (limit > static_cast<uint32_t>(Smi::kMaxValue)) { |
| (...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8300 if (break_point_objects()->IsUndefined()) return 0; | 8293 if (break_point_objects()->IsUndefined()) return 0; |
| 8301 // Single beak point. | 8294 // Single beak point. |
| 8302 if (!break_point_objects()->IsFixedArray()) return 1; | 8295 if (!break_point_objects()->IsFixedArray()) return 1; |
| 8303 // Multiple break points. | 8296 // Multiple break points. |
| 8304 return FixedArray::cast(break_point_objects())->length(); | 8297 return FixedArray::cast(break_point_objects())->length(); |
| 8305 } | 8298 } |
| 8306 #endif | 8299 #endif |
| 8307 | 8300 |
| 8308 | 8301 |
| 8309 } } // namespace v8::internal | 8302 } } // namespace v8::internal |
| OLD | NEW |