Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: src/objects.h

Issue 155350: Changed hash table to use more of the hash value when probing. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 return !k->IsNull() && !k->IsUndefined(); 2044 return !k->IsNull() && !k->IsUndefined();
2045 } 2045 }
2046 2046
2047 // Garbage collection support. 2047 // Garbage collection support.
2048 void IteratePrefix(ObjectVisitor* visitor); 2048 void IteratePrefix(ObjectVisitor* visitor);
2049 void IterateElements(ObjectVisitor* visitor); 2049 void IterateElements(ObjectVisitor* visitor);
2050 2050
2051 // Casting. 2051 // Casting.
2052 static inline HashTable* cast(Object* obj); 2052 static inline HashTable* cast(Object* obj);
2053 2053
2054 // Compute the probe offset (quadratic probing).
2055 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2056 return (n + n * n) >> 1;
2057 }
2058
2059 static const int kNumberOfElementsIndex = 0; 2054 static const int kNumberOfElementsIndex = 0;
2060 static const int kCapacityIndex = 1; 2055 static const int kCapacityIndex = 1;
2061 static const int kPrefixStartIndex = 2; 2056 static const int kPrefixStartIndex = 2;
2062 static const int kElementsStartIndex = 2057 static const int kElementsStartIndex =
2063 kPrefixStartIndex + Shape::kPrefixSize; 2058 kPrefixStartIndex + Shape::kPrefixSize;
2064 static const int kEntrySize = Shape::kEntrySize; 2059 static const int kEntrySize = Shape::kEntrySize;
2065 static const int kElementsStartOffset = 2060 static const int kElementsStartOffset =
2066 kHeaderSize + kElementsStartIndex * kPointerSize; 2061 kHeaderSize + kElementsStartIndex * kPointerSize;
2067 2062
2068 // Constant used for denoting a absent entry. 2063 // Constant used for denoting a absent entry.
2069 static const int kNotFound = -1; 2064 static const int kNotFound = -1;
2070 2065
2071 // Find entry for key otherwise return -1. 2066 // Find entry for key otherwise return -1.
2072 int FindEntry(Key key); 2067 int FindEntry(Key key);
2073 2068
2069 static const uint32_t kNofFastProbes = 4;
2070 static const uint32_t kHashRotateShift = 3;
2071
2074 protected: 2072 protected:
2075 2073
2076 // Find the entry at which to insert element with the given key that 2074 // Find the entry at which to insert element with the given key that
2077 // has the given hash value. 2075 // has the given hash value.
2078 uint32_t FindInsertionEntry(uint32_t hash); 2076 uint32_t FindInsertionEntry(uint32_t hash);
2079 2077
2080 // Returns the index for an entry (of the key) 2078 // Returns the index for an entry (of the key)
2081 static inline int EntryToIndex(int entry) { 2079 static inline int EntryToIndex(int entry) {
2082 return (entry * kEntrySize) + kElementsStartIndex; 2080 return (entry * kEntrySize) + kElementsStartIndex;
2083 } 2081 }
2084 2082
2085 // Update the number of elements in the dictionary. 2083 // Update the number of elements in the dictionary.
2086 void SetNumberOfElements(int nof) { 2084 void SetNumberOfElements(int nof) {
2087 fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); 2085 fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof));
2088 } 2086 }
2089 2087
2090 // Sets the capacity of the hash table. 2088 // Sets the capacity of the hash table.
2091 void SetCapacity(int capacity) { 2089 void SetCapacity(int capacity) {
2092 // To scale a computed hash code to fit within the hash table, we 2090 // To scale a computed hash code to fit within the hash table, we
2093 // use bit-wise AND with a mask, so the capacity must be positive 2091 // use bit-wise AND with a mask, so the capacity must be positive
2094 // and non-zero. 2092 // and non-zero.
2095 ASSERT(capacity > 0); 2093 ASSERT(capacity > 0);
2096 fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); 2094 fast_set(this, kCapacityIndex, Smi::FromInt(capacity));
2097 } 2095 }
2098 2096
2099
2100 // Returns probe entry.
2101 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2102 ASSERT(IsPowerOf2(size));
2103 return (hash + GetProbeOffset(number)) & (size - 1);
2104 }
2105
2106 // Ensure enough space for n additional elements. 2097 // Ensure enough space for n additional elements.
2107 Object* EnsureCapacity(int n, Key key); 2098 Object* EnsureCapacity(int n, Key key);
2108 }; 2099 };
2109 2100
2110 2101
2111 2102
2112 // HashTableKey is an abstract superclass for virtual key behavior. 2103 // HashTableKey is an abstract superclass for virtual key behavior.
2113 class HashTableKey { 2104 class HashTableKey {
2114 public: 2105 public:
2115 // Returns whether the other object matches this key. 2106 // Returns whether the other object matches this key.
(...skipping 2623 matching lines...) Expand 10 before | Expand all | Expand 10 after
4739 } else { 4730 } else {
4740 value &= ~(1 << bit_position); 4731 value &= ~(1 << bit_position);
4741 } 4732 }
4742 return value; 4733 return value;
4743 } 4734 }
4744 }; 4735 };
4745 4736
4746 } } // namespace v8::internal 4737 } } // namespace v8::internal
4747 4738
4748 #endif // V8_OBJECTS_H_ 4739 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698