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

Side by Side Diff: src/objects.h

Issue 523122: Merge r3536 and r3538 to branches/1.3 to fix performance issue... (Closed) Base URL: http://v8.googlecode.com/svn/branches/1.3/
Patch Set: Created 10 years, 11 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
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 // information by subclasses. 2125 // information by subclasses.
2126 2126
2127 template<typename Shape, typename Key> 2127 template<typename Shape, typename Key>
2128 class HashTable: public FixedArray { 2128 class HashTable: public FixedArray {
2129 public: 2129 public:
2130 // Returns the number of elements in the hash table. 2130 // Returns the number of elements in the hash table.
2131 int NumberOfElements() { 2131 int NumberOfElements() {
2132 return Smi::cast(get(kNumberOfElementsIndex))->value(); 2132 return Smi::cast(get(kNumberOfElementsIndex))->value();
2133 } 2133 }
2134 2134
2135 // Returns the number of deleted elements in the hash table.
2136 int NumberOfDeletedElements() {
2137 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
2138 }
2139
2135 // Returns the capacity of the hash table. 2140 // Returns the capacity of the hash table.
2136 int Capacity() { 2141 int Capacity() {
2137 return Smi::cast(get(kCapacityIndex))->value(); 2142 return Smi::cast(get(kCapacityIndex))->value();
2138 } 2143 }
2139 2144
2140 // ElementAdded should be called whenever an element is added to a 2145 // ElementAdded should be called whenever an element is added to a
2141 // hash table. 2146 // hash table.
2142 void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } 2147 void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
2143 2148
2144 // ElementRemoved should be called whenever an element is removed from 2149 // ElementRemoved should be called whenever an element is removed from
2145 // a hash table. 2150 // a hash table.
2146 void ElementRemoved() { SetNumberOfElements(NumberOfElements() - 1); } 2151 void ElementRemoved() {
2147 void ElementsRemoved(int n) { SetNumberOfElements(NumberOfElements() - n); } 2152 SetNumberOfElements(NumberOfElements() - 1);
2153 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
2154 }
2155 void ElementsRemoved(int n) {
2156 SetNumberOfElements(NumberOfElements() - n);
2157 SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
2158 }
2148 2159
2149 // Returns a new HashTable object. Might return Failure. 2160 // Returns a new HashTable object. Might return Failure.
2150 static Object* Allocate(int at_least_space_for); 2161 static Object* Allocate(int at_least_space_for);
2151 2162
2152 // Returns the key at entry. 2163 // Returns the key at entry.
2153 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } 2164 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
2154 2165
2155 // Tells whether k is a real key. Null and undefined are not allowed 2166 // Tells whether k is a real key. Null and undefined are not allowed
2156 // as keys and can be used to indicate missing or deleted elements. 2167 // as keys and can be used to indicate missing or deleted elements.
2157 bool IsKey(Object* k) { 2168 bool IsKey(Object* k) {
2158 return !k->IsNull() && !k->IsUndefined(); 2169 return !k->IsNull() && !k->IsUndefined();
2159 } 2170 }
2160 2171
2161 // Garbage collection support. 2172 // Garbage collection support.
2162 void IteratePrefix(ObjectVisitor* visitor); 2173 void IteratePrefix(ObjectVisitor* visitor);
2163 void IterateElements(ObjectVisitor* visitor); 2174 void IterateElements(ObjectVisitor* visitor);
2164 2175
2165 // Casting. 2176 // Casting.
2166 static inline HashTable* cast(Object* obj); 2177 static inline HashTable* cast(Object* obj);
2167 2178
2168 // Compute the probe offset (quadratic probing). 2179 // Compute the probe offset (quadratic probing).
2169 INLINE(static uint32_t GetProbeOffset(uint32_t n)) { 2180 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2170 return (n + n * n) >> 1; 2181 return (n + n * n) >> 1;
2171 } 2182 }
2172 2183
2173 static const int kNumberOfElementsIndex = 0; 2184 static const int kNumberOfElementsIndex = 0;
2174 static const int kCapacityIndex = 1; 2185 static const int kNumberOfDeletedElementsIndex = 1;
2175 static const int kPrefixStartIndex = 2; 2186 static const int kCapacityIndex = 2;
2176 static const int kElementsStartIndex = 2187 static const int kPrefixStartIndex = 3;
2188 static const int kElementsStartIndex =
2177 kPrefixStartIndex + Shape::kPrefixSize; 2189 kPrefixStartIndex + Shape::kPrefixSize;
2178 static const int kEntrySize = Shape::kEntrySize; 2190 static const int kEntrySize = Shape::kEntrySize;
2179 static const int kElementsStartOffset = 2191 static const int kElementsStartOffset =
2180 kHeaderSize + kElementsStartIndex * kPointerSize; 2192 kHeaderSize + kElementsStartIndex * kPointerSize;
2181 2193
2182 // Constant used for denoting a absent entry. 2194 // Constant used for denoting a absent entry.
2183 static const int kNotFound = -1; 2195 static const int kNotFound = -1;
2184 2196
2185 // Find entry for key otherwise return -1. 2197 // Find entry for key otherwise return -1.
2186 int FindEntry(Key key); 2198 int FindEntry(Key key);
2187 2199
2188 protected: 2200 protected:
2189 2201
2190 // Find the entry at which to insert element with the given key that 2202 // Find the entry at which to insert element with the given key that
2191 // has the given hash value. 2203 // has the given hash value.
2192 uint32_t FindInsertionEntry(uint32_t hash); 2204 uint32_t FindInsertionEntry(uint32_t hash);
2193 2205
2194 // Returns the index for an entry (of the key) 2206 // Returns the index for an entry (of the key)
2195 static inline int EntryToIndex(int entry) { 2207 static inline int EntryToIndex(int entry) {
2196 return (entry * kEntrySize) + kElementsStartIndex; 2208 return (entry * kEntrySize) + kElementsStartIndex;
2197 } 2209 }
2198 2210
2199 // Update the number of elements in the hash table. 2211 // Update the number of elements in the hash table.
2200 void SetNumberOfElements(int nof) { 2212 void SetNumberOfElements(int nof) {
2201 fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); 2213 fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof));
2202 } 2214 }
2203 2215
2216 // Update the number of deleted elements in the hash table.
2217 void SetNumberOfDeletedElements(int nod) {
2218 fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
2219 }
2220
2204 // Sets the capacity of the hash table. 2221 // Sets the capacity of the hash table.
2205 void SetCapacity(int capacity) { 2222 void SetCapacity(int capacity) {
2206 // To scale a computed hash code to fit within the hash table, we 2223 // To scale a computed hash code to fit within the hash table, we
2207 // use bit-wise AND with a mask, so the capacity must be positive 2224 // use bit-wise AND with a mask, so the capacity must be positive
2208 // and non-zero. 2225 // and non-zero.
2209 ASSERT(capacity > 0); 2226 ASSERT(capacity > 0);
2210 fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); 2227 fast_set(this, kCapacityIndex, Smi::FromInt(capacity));
2211 } 2228 }
2212 2229
2213 2230
(...skipping 2952 matching lines...) Expand 10 before | Expand all | Expand 10 after
5166 } else { 5183 } else {
5167 value &= ~(1 << bit_position); 5184 value &= ~(1 << bit_position);
5168 } 5185 }
5169 return value; 5186 return value;
5170 } 5187 }
5171 }; 5188 };
5172 5189
5173 } } // namespace v8::internal 5190 } } // namespace v8::internal
5174 5191
5175 #endif // V8_OBJECTS_H_ 5192 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698