Ignore:
Timestamp:
Apr 28, 2008, 10:18:15 AM (17 years ago)
Author:
Darin Adler
Message:

2008-04-28 Darin Adler <Darin Adler>

Reviewed by Adam.

  • make sure RefPtr's default hash doesn't ref/deref when computing the hash
  • remove remnants of the hash table storage type optimization
  • wtf/HashFunctions.h: Used "using" to get the hash and equal functions from PtrHash<P*> into PtrHash<RefPtr<P>>.
  • wtf/HashMap.h: Replaced uses of PairBaseHashTraits with PairHashTraits. Eliminated storage-related typedefs. Removed constructor, destructor, copy constructor, and destructor since the compiler-generated ones are fine. Removed refAll and derefAll. Took out unnnecessary typecasts. Removed use of RefCounter.
  • wtf/HashSet.h: Eliminated storage-related typedefs. Removed constructor, destructor, copy constructor, and destructor since the compiler-generated ones are fine. Removed refAll and derefAll. Removed unneeded template arguents from HashSetTranslatorAdapter. Eliminated unneeded HashSetTranslator template.
  • wtf/HashTable.h: Tweaked formatting. Removed NeedsRef, RefCounterBase, RefCounter, HashTableRefCounterBase, HashTableRefCounter, and Assigner class templates.
  • wtf/HashTraits.h: Removed StorageTraits, needsRef, PairBaseHashTraits, and HashKeyStorageTraits.
  • wtf/RefPtrHashMap.h: Made all the same fixes as in HashMap. Also made the corresponding changes to RefPtrHashMapRawKeyTranslator.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/RefPtrHashMap.h

    r32609 r32650  
    2525    // to allow for lookup by pointer instead of RefPtr, avoiding ref-count churn.
    2626   
    27     // FIXME: Is there a better way to do this that doesn't just copy HashMap?
     27    // FIXME: Find a better way that doesn't require an entire copy of the HashMap template.
    2828   
    29     template<typename RawKeyType, typename ValueType, typename ValueTraits, typename ValueStorageTraits, typename HashFunctions>
     29    template<typename RawKeyType, typename ValueType, typename ValueTraits, typename HashFunctions>
    3030    struct RefPtrHashMapRawKeyTranslator {
    3131        typedef typename ValueType::first_type KeyType;
    3232        typedef typename ValueType::second_type MappedType;
    33         typedef typename ValueStorageTraits::TraitType ValueStorageType;
    34         typedef typename ValueStorageTraits::FirstTraits KeyStorageTraits;
    35         typedef typename KeyStorageTraits::TraitType KeyStorageType;
    36         typedef typename ValueStorageTraits::SecondTraits MappedStorageTraits;
    37         typedef typename MappedStorageTraits::TraitType MappedStorageType;
    3833        typedef typename ValueTraits::FirstTraits KeyTraits;
    3934        typedef typename ValueTraits::SecondTraits MappedTraits;
    4035
    4136        static unsigned hash(RawKeyType key) { return HashFunctions::hash(key); }
    42         static bool equal(const KeyStorageType& a, RawKeyType b) { return HashFunctions::equal(*(KeyType*)&a, b); }
    43         static void translate(ValueStorageType& location, RawKeyType key, const MappedType& mapped)
     37        static bool equal(const KeyType& a, RawKeyType b) { return HashFunctions::equal(a, b); }
     38        static void translate(ValueType& location, RawKeyType key, const MappedType& mapped)
    4439        {
    4540            location.first = key;
     
    5348        typedef KeyTraitsArg KeyTraits;
    5449        typedef MappedTraitsArg MappedTraits;
    55         typedef PairBaseHashTraits<KeyTraits, MappedTraits> ValueTraits;
     50        typedef PairHashTraits<KeyTraits, MappedTraits> ValueTraits;
    5651
    5752    public:
     
    6459        typedef HashArg HashFunctions;
    6560
    66         typedef typename HashKeyStorageTraits<HashFunctions, KeyTraits>::Hash StorageHashFunctions;
    67 
    68         typedef typename HashKeyStorageTraits<HashFunctions, KeyTraits>::Traits KeyStorageTraits;
    69         typedef typename MappedTraits::StorageTraits MappedStorageTraits;
    70         typedef PairHashTraits<KeyStorageTraits, MappedStorageTraits> ValueStorageTraits;
    71 
    72         typedef typename KeyStorageTraits::TraitType KeyStorageType;
    73         typedef typename MappedStorageTraits::TraitType MappedStorageType;
    74         typedef typename ValueStorageTraits::TraitType ValueStorageType;
    75 
    76         typedef HashTable<KeyStorageType, ValueStorageType, PairFirstExtractor<ValueStorageType>,
    77             StorageHashFunctions, ValueStorageTraits, KeyStorageTraits> HashTableType;
    78 
    79         typedef RefPtrHashMapRawKeyTranslator<RawKeyType, ValueType, ValueTraits, ValueStorageTraits, HashFunctions>
     61        typedef HashTable<KeyType, ValueType, PairFirstExtractor<ValueType>,
     62            HashFunctions, ValueTraits, KeyTraits> HashTableType;
     63
     64        typedef RefPtrHashMapRawKeyTranslator<RawKeyType, ValueType, ValueTraits, HashFunctions>
    8065            RawKeyTranslator;
    8166
     
    8368        typedef HashTableIteratorAdapter<HashTableType, ValueType> iterator;
    8469        typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator;
    85 
    86         HashMap();
    87         HashMap(const HashMap&);
    88         HashMap& operator=(const HashMap&);
    89         ~HashMap();
    9070
    9171        void swap(HashMap&);
     
    134114        pair<iterator, bool> inlineAdd(const KeyType&, const MappedType&);
    135115        pair<iterator, bool> inlineAdd(RawKeyType, const MappedType&);
    136         void refAll();
    137         void derefAll();
    138116
    139117        HashTableType m_impl;
     
    141119   
    142120    template<typename T, typename U, typename V, typename W, typename X>
    143     inline void HashMap<RefPtr<T>, U, V, W, X>::refAll()
    144     {
    145         HashTableRefCounter<HashTableType, ValueTraits>::refAll(m_impl);
    146     }
    147 
    148     template<typename T, typename U, typename V, typename W, typename X>
    149     inline void HashMap<RefPtr<T>, U, V, W, X>::derefAll()
    150     {
    151         HashTableRefCounter<HashTableType, ValueTraits>::derefAll(m_impl);
    152     }
    153 
    154     template<typename T, typename U, typename V, typename W, typename X>
    155     inline HashMap<RefPtr<T>, U, V, W, X>::HashMap()
    156     {
    157     }
    158 
    159     template<typename T, typename U, typename V, typename W, typename X>
    160     inline HashMap<RefPtr<T>, U, V, W, X>::HashMap(const HashMap& other)
    161         : m_impl(other.m_impl)
    162     {
    163         refAll();
    164     }
    165 
    166     template<typename T, typename U, typename V, typename W, typename X>
    167     inline HashMap<RefPtr<T>, U, V, W, X>& HashMap<RefPtr<T>, U, V, W, X>::operator=(const HashMap& other)
    168     {
    169         HashMap tmp(other);
    170         swap(tmp);
    171         return *this;
    172     }
    173 
    174     template<typename T, typename U, typename V, typename W, typename X>
    175121    inline void HashMap<RefPtr<T>, U, V, W, X>::swap(HashMap& other)
    176122    {
    177123        m_impl.swap(other.m_impl);
    178     }
    179 
    180     template<typename T, typename U, typename V, typename W, typename X>
    181     inline HashMap<RefPtr<T>, U, V, W, X>::~HashMap()
    182     {
    183         derefAll();
    184124    }
    185125
     
    229169    inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::find(const KeyType& key)
    230170    {
    231         return m_impl.find(*(const KeyStorageType*)&key);
     171        return m_impl.find(key);
    232172    }
    233173
     
    241181    inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::find(const KeyType& key) const
    242182    {
    243         return m_impl.find(*(const KeyStorageType*)&key);
     183        return m_impl.find(key);
    244184    }
    245185
     
    253193    inline bool HashMap<RefPtr<T>, U, V, W, X>::contains(const KeyType& key) const
    254194    {
    255         return m_impl.contains(*(const KeyStorageType*)&key);
     195        return m_impl.contains(key);
    256196    }
    257197
     
    266206    HashMap<RefPtr<T>, U, V, W, X>::inlineAdd(const KeyType& key, const MappedType& mapped)
    267207    {
    268         const bool canReplaceDeletedKey = !KeyTraits::needsDestruction || KeyStorageTraits::needsDestruction;
    269         typedef HashMapTranslator<canReplaceDeletedKey, ValueType, ValueTraits, ValueStorageTraits, HashFunctions> TranslatorType;
     208        typedef HashMapTranslator<ValueType, ValueTraits, HashFunctions> TranslatorType;
    270209        return m_impl.template add<KeyType, MappedType, TranslatorType>(key, mapped);
    271210    }
     
    320259    HashMap<RefPtr<T>, U, V, W, MappedTraits>::get(const KeyType& key) const
    321260    {
    322         ValueStorageType* entry = const_cast<HashTableType&>(m_impl).lookup(*(const KeyStorageType*)&key);
     261        ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key);
    323262        if (!entry)
    324263            return MappedTraits::emptyValue();
    325         return ((ValueType *)entry)->second;
     264        return entry->second;
    326265    }
    327266
     
    349288            return;
    350289        m_impl.checkTableConsistency();
    351         RefCounter<ValueTraits, ValueStorageTraits>::deref(*it.m_impl);
    352290        m_impl.removeWithoutEntryConsistencyCheck(it.m_impl);
    353291    }
     
    368306    inline void HashMap<RefPtr<T>, U, V, W, X>::clear()
    369307    {
    370         derefAll();
    371308        m_impl.clear();
    372309    }
Note: See TracChangeset for help on using the changeset viewer.