Changeset 143071 in webkit


Ignore:
Timestamp:
Feb 15, 2013 5:01:03 PM (11 years ago)
Author:
andersca@apple.com
Message:

Add HashMap::isValidKey and HashSet::isValidValue
https://bugs.webkit.org/show_bug.cgi?id=109977

Reviewed by Sam Weinig and Darin Adler.

Source/WebKit2:

Just call HashMap::isValidKey directly.

  • UIProcess/WebProcessProxy.cpp:

(WebKit::generatePageID):
Initialize the id to 0 and use prefix increment.

(WebKit::WebProcessProxy::webFrame):
(WebKit::WebProcessProxy::canCreateFrame):
(WebKit::WebProcessProxy::didDestroyFrame):

Source/WTF:

Add helper functions for determining whether keys are valid, i.e. if
they are _not_ empty or deleted according to the hash traits.

  • wtf/HashMap.h:
  • wtf/HashSet.h:
Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r143061 r143071  
     12013-02-15  Anders Carlsson  <andersca@apple.com>
     2
     3        Add HashMap::isValidKey and HashSet::isValidValue
     4        https://bugs.webkit.org/show_bug.cgi?id=109977
     5
     6        Reviewed by Sam Weinig and Darin Adler.
     7
     8        Add helper functions for determining whether keys are valid, i.e. if
     9        they are _not_ empty or deleted according to the hash traits.
     10
     11        * wtf/HashMap.h:
     12        * wtf/HashSet.h:
     13
    1142013-02-15  Laszlo Gombos  <l.gombos@samsung.com>
    215
  • trunk/Source/WTF/wtf/HashMap.h

    r130612 r143071  
    132132        void checkConsistency() const;
    133133
     134        static bool isValidKey(const KeyType&);
     135
    134136    private:
    135137        AddResult inlineAdd(const KeyType&, MappedPassInReferenceType);
     
    412414
    413415    template<typename T, typename U, typename V, typename W, typename X>
     416    inline bool HashMap<T, U, V, W, X>::isValidKey(const KeyType& key)
     417    {
     418        if (KeyTraits::isDeletedValue(key))
     419            return false;
     420
     421        if (HashFunctions::safeToCompareToEmptyOrDeleted) {
     422            if (key == KeyTraits::emptyValue())
     423                return false;
     424        } else {
     425            if (isHashTraitsEmptyValue<KeyTraits>(key))
     426                return false;
     427        }
     428
     429        return true;
     430    }
     431
     432    template<typename T, typename U, typename V, typename W, typename X>
    414433    bool operator==(const HashMap<T, U, V, W, X>& a, const HashMap<T, U, V, W, X>& b)
    415434    {
  • trunk/Source/WTF/wtf/HashSet.h

    r131362 r143071  
    9292        void clear();
    9393
     94        static bool isValidValue(const ValueType&);
     95
    9496    private:
    9597        friend void deleteAllValues<>(const HashSet&);
     
    210212    }
    211213
     214    template<typename T, typename U, typename V>
     215    inline bool HashSet<T, U, V>::isValidValue(const ValueType& value)
     216    {
     217        if (ValueTraits::isDeletedValue(value))
     218            return false;
     219
     220        if (HashFunctions::safeToCompareToEmptyOrDeleted) {
     221            if (value == ValueTraits::emptyValue())
     222                return false;
     223        } else {
     224            if (isHashTraitsEmptyValue<ValueTraits>(value))
     225                return false;
     226        }
     227
     228        return true;
     229    }
     230
    212231    template<typename ValueType, typename HashTableType>
    213232    void deleteAllValues(HashTableType& collection)
  • trunk/Source/WebKit2/ChangeLog

    r143065 r143071  
     12013-02-15  Anders Carlsson  <andersca@apple.com>
     2
     3        Add HashMap::isValidKey and HashSet::isValidValue
     4        https://bugs.webkit.org/show_bug.cgi?id=109977
     5
     6        Reviewed by Sam Weinig and Darin Adler.
     7
     8        Just call HashMap::isValidKey directly.
     9
     10        * UIProcess/WebProcessProxy.cpp:
     11        (WebKit::generatePageID):
     12        Initialize the id to 0 and use prefix increment.
     13
     14        (WebKit::WebProcessProxy::webFrame):
     15        (WebKit::WebProcessProxy::canCreateFrame):
     16        (WebKit::WebProcessProxy::didDestroyFrame):
     17
    1182013-02-15  Csaba Osztrogonác  <ossy@webkit.org>
    219
  • trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp

    r142656 r143071  
    7070namespace WebKit {
    7171
    72 template<typename HashMap>
    73 static inline bool isGoodKey(const typename HashMap::KeyType& key)
    74 {
    75     return key != HashTraits<typename HashMap::KeyType>::emptyValue() && !HashTraits<typename HashMap::KeyType>::isDeletedValue(key);
    76 }
    77 
    7872static uint64_t generatePageID()
    7973{
    80     static uint64_t uniquePageID = 1;
    81     return uniquePageID++;
     74    static uint64_t uniquePageID;
     75    return ++uniquePageID;
    8276}
    8377
     
    459453WebFrameProxy* WebProcessProxy::webFrame(uint64_t frameID) const
    460454{
    461     return isGoodKey<WebFrameProxyMap>(frameID) ? m_frameMap.get(frameID).get() : 0;
     455    if (!WebFrameProxyMap::isValidKey(frameID))
     456        return 0;
     457
     458    return m_frameMap.get(frameID).get();
    462459}
    463460
    464461bool WebProcessProxy::canCreateFrame(uint64_t frameID) const
    465462{
    466     return isGoodKey<WebFrameProxyMap>(frameID) && !m_frameMap.contains(frameID);
     463    return WebFrameProxyMap::isValidKey(frameID) && !m_frameMap.contains(frameID);
    467464}
    468465
     
    478475    // back to the UIProcess, then the frameDestroyed message will still be received because it
    479476    // gets sent directly to the WebProcessProxy.
    480     ASSERT(isGoodKey<WebFrameProxyMap>(frameID));
     477    ASSERT(WebFrameProxyMap::isValidKey(frameID));
    481478    m_frameMap.remove(frameID);
    482479}
Note: See TracChangeset for help on using the changeset viewer.