Commit 5287d48b authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[cleanup] Remove Key template parameter from HashTable and Dictionary

Shape also contains the Key type. Read it through there instead.

Bug: v8:6474
Also-By: cbruni@chromium.org
Change-Id: Ia47f6143c671c104901a714d4151c9fe9f525b5f
Reviewed-on: https://chromium-review.googlesource.com/529305Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45818}
parent 0d704379
......@@ -2945,21 +2945,20 @@ Map* BaseShape<Key>::GetMap(Isolate* isolate) {
return isolate->heap()->hash_table_map();
}
template <typename Derived, typename Shape, typename Key>
int HashTable<Derived, Shape, Key>::FindEntry(Key key) {
template <typename Derived, typename Shape>
int HashTable<Derived, Shape>::FindEntry(Key key) {
return FindEntry(GetIsolate(), key);
}
template<typename Derived, typename Shape, typename Key>
int HashTable<Derived, Shape, Key>::FindEntry(Isolate* isolate, Key key) {
template <typename Derived, typename Shape>
int HashTable<Derived, Shape>::FindEntry(Isolate* isolate, Key key) {
return FindEntry(isolate, key, HashTable::Hash(key));
}
// Find entry for key otherwise return kNotFound.
template <typename Derived, typename Shape, typename Key>
int HashTable<Derived, Shape, Key>::FindEntry(Isolate* isolate, Key key,
int32_t hash) {
template <typename Derived, typename Shape>
int HashTable<Derived, Shape>::FindEntry(Isolate* isolate, Key key,
int32_t hash) {
uint32_t capacity = Capacity();
uint32_t entry = FirstProbe(hash, capacity);
uint32_t count = 1;
......@@ -2977,13 +2976,13 @@ int HashTable<Derived, Shape, Key>::FindEntry(Isolate* isolate, Key key,
return kNotFound;
}
template <typename Derived, typename Shape, typename Key>
bool HashTable<Derived, Shape, Key>::Has(Key key) {
template <typename Derived, typename Shape>
bool HashTable<Derived, Shape>::Has(Key key) {
return FindEntry(key) != kNotFound;
}
template <typename Derived, typename Shape, typename Key>
bool HashTable<Derived, Shape, Key>::Has(Isolate* isolate, Key key) {
template <typename Derived, typename Shape>
bool HashTable<Derived, Shape>::Has(Isolate* isolate, Key key) {
return FindEntry(isolate, key) != kNotFound;
}
......@@ -3175,17 +3174,15 @@ int HandlerTable::NumberOfRangeEntries() const {
return length() / kRangeEntrySize;
}
template <typename Derived, typename Shape, typename Key>
HashTable<Derived, Shape, Key>*
HashTable<Derived, Shape, Key>::cast(Object* obj) {
template <typename Derived, typename Shape>
HashTable<Derived, Shape>* HashTable<Derived, Shape>::cast(Object* obj) {
SLOW_DCHECK(obj->IsHashTable());
return reinterpret_cast<HashTable*>(obj);
}
template <typename Derived, typename Shape, typename Key>
const HashTable<Derived, Shape, Key>*
HashTable<Derived, Shape, Key>::cast(const Object* obj) {
template <typename Derived, typename Shape>
const HashTable<Derived, Shape>* HashTable<Derived, Shape>::cast(
const Object* obj) {
SLOW_DCHECK(obj->IsHashTable());
return reinterpret_cast<const HashTable*>(obj);
}
......@@ -6930,20 +6927,16 @@ bool AccessorPair::IsJSAccessor(Object* obj) {
return obj->IsCallable() || obj->IsUndefined(GetIsolate());
}
template<typename Derived, typename Shape, typename Key>
void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
Handle<Object> key,
Handle<Object> value) {
template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::SetEntry(int entry, Handle<Object> key,
Handle<Object> value) {
this->SetEntry(entry, key, value, PropertyDetails(Smi::kZero));
}
template<typename Derived, typename Shape, typename Key>
void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
Handle<Object> key,
Handle<Object> value,
PropertyDetails details) {
template <typename Derived, typename Shape>
void Dictionary<Derived, Shape>::SetEntry(int entry, Handle<Object> key,
Handle<Object> value,
PropertyDetails details) {
Shape::SetEntry(static_cast<Derived*>(this), entry, key, value, details);
}
......
This diff is collapsed.
......@@ -36,8 +36,7 @@ class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
};
class CodeCacheHashTable
: public HashTable<CodeCacheHashTable, CodeCacheHashTableShape,
HashTableKey*> {
: public HashTable<CodeCacheHashTable, CodeCacheHashTableShape> {
public:
static Handle<CodeCacheHashTable> Put(Handle<CodeCacheHashTable> table,
Handle<Name> name, Handle<Code> code);
......
......@@ -60,8 +60,7 @@ class InfoVectorPair {
// recompilation stub, or to "old" code. This avoids memory leaks due to
// premature caching of scripts and eval strings that are never needed later.
class CompilationCacheTable
: public HashTable<CompilationCacheTable, CompilationCacheShape,
HashTableKey*> {
: public HashTable<CompilationCacheTable, CompilationCacheShape> {
public:
// Find cached value for a string key, otherwise return null.
Handle<Object> Lookup(Handle<String> src, Handle<Context> context,
......
......@@ -21,11 +21,12 @@ class Handle;
class Isolate;
template <typename Derived, typename Shape, typename Key>
class Dictionary : public HashTable<Derived, Shape, Key> {
typedef HashTable<Derived, Shape, Key> DerivedHashTable;
template <typename Derived, typename Shape>
class Dictionary : public HashTable<Derived, Shape> {
typedef HashTable<Derived, Shape> DerivedHashTable;
public:
typedef typename Shape::Key Key;
// Returns the value at entry.
Object* ValueAt(int entry) {
return this->get(Derived::EntryToIndex(entry) + 1);
......@@ -66,15 +67,15 @@ class Dictionary : public HashTable<Derived, Shape, Key> {
// Return the key indices sorted by its enumeration index.
static Handle<FixedArray> IterationIndices(
Handle<Dictionary<Derived, Shape, Key>> dictionary);
Handle<Dictionary<Derived, Shape>> dictionary);
// Collect the keys into the given KeyAccumulator, in ascending chronological
// order of property creation.
static void CollectKeysTo(Handle<Dictionary<Derived, Shape, Key>> dictionary,
static void CollectKeysTo(Handle<Dictionary<Derived, Shape>> dictionary,
KeyAccumulator* keys);
// Copies enumerable keys to preallocated fixed array.
static void CopyEnumKeysTo(Handle<Dictionary<Derived, Shape, Key>> dictionary,
static void CopyEnumKeysTo(Handle<Dictionary<Derived, Shape>> dictionary,
Handle<FixedArray> storage, KeyCollectionMode mode,
KeyAccumulator* accumulator);
......@@ -138,8 +139,8 @@ class Dictionary : public HashTable<Derived, Shape, Key> {
};
template <typename Derived, typename Shape>
class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name>> {
typedef Dictionary<Derived, Shape, Handle<Name>> DerivedDictionary;
class NameDictionaryBase : public Dictionary<Derived, Shape> {
typedef Dictionary<Derived, Shape> DerivedDictionary;
public:
// Find entry for key, otherwise return kNotFound. Optimized version of
......@@ -270,14 +271,13 @@ class UnseededNumberDictionaryShape : public NumberDictionaryShape {
};
extern template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE)
HashTable<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>;
HashTable<SeededNumberDictionary, SeededNumberDictionaryShape>;
extern template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE)
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>;
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape>;
class SeededNumberDictionary
: public Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
uint32_t> {
: public Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape> {
public:
DECLARE_CAST(SeededNumberDictionary)
......@@ -333,8 +333,8 @@ class SeededNumberDictionary
};
class UnseededNumberDictionary
: public Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape,
uint32_t> {
: public Dictionary<UnseededNumberDictionary,
UnseededNumberDictionaryShape> {
public:
DECLARE_CAST(UnseededNumberDictionary)
......
......@@ -49,9 +49,10 @@ namespace internal {
// beginning of the backing storage that can be used for non-element
// information by subclasses.
template <typename Key>
template <typename KeyT>
class BaseShape {
public:
typedef KeyT Key;
static const bool UsesSeed = false;
static uint32_t Hash(Key key) { return 0; }
static uint32_t SeededHash(Key key, uint32_t seed) {
......@@ -133,10 +134,11 @@ class V8_EXPORT_PRIVATE HashTableBase : public NON_EXPORTED_BASE(FixedArray) {
}
};
template <typename Derived, typename Shape, typename Key>
template <typename Derived, typename Shape>
class HashTable : public HashTableBase {
public:
typedef Shape ShapeT;
typedef typename Shape::Key Key;
// Wrapper methods
inline uint32_t Hash(Key key) {
......@@ -279,9 +281,8 @@ class ObjectHashTableShape : public BaseShape<Handle<Object>> {
// ObjectHashTable maps keys that are arbitrary objects to object values by
// using the identity hash of the key for hashing purposes.
class ObjectHashTable
: public HashTable<ObjectHashTable, ObjectHashTableShape, Handle<Object>> {
typedef HashTable<ObjectHashTable, ObjectHashTableShape, Handle<Object>>
DerivedHashTable;
: public HashTable<ObjectHashTable, ObjectHashTableShape> {
typedef HashTable<ObjectHashTable, ObjectHashTableShape> DerivedHashTable;
public:
DECLARE_CAST(ObjectHashTable)
......@@ -331,8 +332,7 @@ class ObjectHashSetShape : public ObjectHashTableShape {
static const int kEntrySize = 1;
};
class ObjectHashSet
: public HashTable<ObjectHashSet, ObjectHashSetShape, Handle<Object>> {
class ObjectHashSet : public HashTable<ObjectHashSet, ObjectHashSetShape> {
public:
static Handle<ObjectHashSet> Add(Handle<ObjectHashSet> set,
Handle<Object> key);
......@@ -564,10 +564,8 @@ class WeakHashTableShape : public BaseShape<Handle<Object>> {
// WeakHashTable maps keys that are arbitrary heap objects to heap object
// values. The table wraps the keys in weak cells and store values directly.
// Thus it references keys weakly and values strongly.
class WeakHashTable
: public HashTable<WeakHashTable, WeakHashTableShape<2>, Handle<Object>> {
typedef HashTable<WeakHashTable, WeakHashTableShape<2>, Handle<Object>>
DerivedHashTable;
class WeakHashTable : public HashTable<WeakHashTable, WeakHashTableShape<2>> {
typedef HashTable<WeakHashTable, WeakHashTableShape<2>> DerivedHashTable;
public:
DECLARE_CAST(WeakHashTable)
......
......@@ -37,8 +37,7 @@ class SeqOneByteString;
//
// No special elements in the prefix and the element size is 1
// because only the string itself (the key) needs to be stored.
class StringTable
: public HashTable<StringTable, StringTableShape, HashTableKey*> {
class StringTable : public HashTable<StringTable, StringTableShape> {
public:
// Find string in the string table. If it is not there yet, it is
// added. The return value is the string found.
......@@ -81,7 +80,7 @@ class StringSetShape : public BaseShape<String*> {
static const int kEntrySize = 1;
};
class StringSet : public HashTable<StringSet, StringSetShape, String*> {
class StringSet : public HashTable<StringSet, StringSetShape> {
public:
static Handle<StringSet> New(Isolate* isolate);
static Handle<StringSet> Add(Handle<StringSet> blacklist,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment