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

Unified Diff: src/objects.h

Issue 9148006: [objects] seed NumberDictionary (only ia32 now) Base URL: gh:v8/v8@master
Patch Set: added test, decoupled code Created 8 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 side-by-side diff with in-line comments
Download patch
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 717b2ab07204c4f8155cb55cf5927067c3d7083b..728413eb95fca1859294016113075c90cd25741f 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -2588,9 +2588,44 @@ class DescriptorArray: public FixedArray {
// beginning of the backing storage that can be used for non-element
// information by subclasses.
+template<typename Key>
+class BaseShape {
+ public:
+ static const bool UsesSeed = false;
+ static uint32_t Hash(Key key) { return 0; }
+ static uint32_t SeededHash(Key key, uint32_t seed) {
+ // Won't be called if UsesSeed isn't overrided by child class
Erik Corry 2012/01/10 11:53:16 overrided ->overridden
+ return Hash(key);
+ }
+ static uint32_t HashForObject(Key key, Object* object) { return 0; }
+ static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
+ // Won't be called if UsesSeed isn't overrided by child class
Erik Corry 2012/01/10 11:53:16 And here.
+ return HashForObject(key, object);
+ }
+};
+
template<typename Shape, typename Key>
class HashTable: public FixedArray {
public:
+ // Wrapper methods
+ inline uint32_t Hash(Key key) {
+ if (Shape::UsesSeed) {
+ return Shape::SeededHash(key,
+ GetHeap()->StringHashSeed());
+ } else {
+ return Shape::Hash(key);
+ }
+ }
+
+ inline uint32_t HashForObject(Key key, Object* object) {
+ if (Shape::UsesSeed) {
+ return Shape::SeededHashForObject(key,
+ GetHeap()->StringHashSeed(), object);
+ } else {
+ return Shape::HashForObject(key, object);
+ }
+ }
+
// Returns the number of elements in the hash table.
int NumberOfElements() {
return Smi::cast(get(kNumberOfElementsIndex))->value();
@@ -2749,7 +2784,7 @@ class HashTableKey {
virtual ~HashTableKey() {}
};
Erik Corry 2012/01/10 11:53:16 There's a missing blank line here.
-class SymbolTableShape {
+class SymbolTableShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Object* value) {
return key->IsMatch(value);
@@ -2808,7 +2843,7 @@ class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
};
-class MapCacheShape {
+class MapCacheShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Object* value) {
return key->IsMatch(value);
@@ -2964,7 +2999,7 @@ class Dictionary: public HashTable<Shape, Key> {
};
-class StringDictionaryShape {
+class StringDictionaryShape : public BaseShape<String*> {
public:
static inline bool IsMatch(String* key, Object* other);
static inline uint32_t Hash(String* key);
@@ -2997,11 +3032,16 @@ class StringDictionary: public Dictionary<StringDictionaryShape, String*> {
};
-class NumberDictionaryShape {
+class NumberDictionaryShape : public BaseShape<uint32_t> {
public:
+ static const bool UsesSeed = true;
+
static inline bool IsMatch(uint32_t key, Object* other);
static inline uint32_t Hash(uint32_t key);
+ static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
static inline uint32_t HashForObject(uint32_t key, Object* object);
+ static inline uint32_t SeededHashForObject(uint32_t key, uint32_t seed,
Erik Corry 2012/01/10 11:53:16 Formatting.
+ Object* object);
MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key);
static const int kPrefixSize = 2;
static const int kEntrySize = 3;
@@ -3057,7 +3097,7 @@ class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> {
template <int entrysize>
-class ObjectHashTableShape {
+class ObjectHashTableShape : public BaseShape<Object*> {
public:
static inline bool IsMatch(Object* key, Object* other);
static inline uint32_t Hash(Object* key);
@@ -5969,7 +6009,7 @@ class JSRegExp: public JSObject {
};
-class CompilationCacheShape {
+class CompilationCacheShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Object* value) {
return key->IsMatch(value);
@@ -6073,7 +6113,7 @@ class CodeCache: public Struct {
};
-class CodeCacheHashTableShape {
+class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
public:
static inline bool IsMatch(HashTableKey* key, Object* value) {
return key->IsMatch(value);

Powered by Google App Engine
This is Rietveld 408576698