diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-19 19:15:32 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-19 19:15:32 +0000 |
commit | 96edb648e2ea10e1662758b791fc7b494fe74f49 (patch) | |
tree | 151255322f5b38a92ad0e4faa1d49b9a0925ad26 /include/llvm/ADT/ValueMap.h | |
parent | 4e4c3408a5a1cc72b739a4b448329a281c379c55 (diff) | |
download | llvm-96edb648e2ea10e1662758b791fc7b494fe74f49.tar.gz llvm-96edb648e2ea10e1662758b791fc7b494fe74f49.tar.bz2 llvm-96edb648e2ea10e1662758b791fc7b494fe74f49.tar.xz |
ValueMap: Use DenseMap's find_as mechanism to reduce use list churn.
Otherwise just looking up a value in the map requires creating a VH, adding it to the use lists and destroying it again.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157124 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/ValueMap.h')
-rw-r--r-- | include/llvm/ADT/ValueMap.h | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/include/llvm/ADT/ValueMap.h b/include/llvm/ADT/ValueMap.h index 707d07d32c..121abc2b65 100644 --- a/include/llvm/ADT/ValueMap.h +++ b/include/llvm/ADT/ValueMap.h @@ -111,20 +111,21 @@ public: /// count - Return true if the specified key is in the map. bool count(const KeyT &Val) const { - return Map.count(Wrap(Val)); + return Map.find_as(Val) != Map.end(); } iterator find(const KeyT &Val) { - return iterator(Map.find(Wrap(Val))); + return iterator(Map.find_as(Val)); } const_iterator find(const KeyT &Val) const { - return const_iterator(Map.find(Wrap(Val))); + return const_iterator(Map.find_as(Val)); } /// lookup - Return the entry for the specified key, or a default /// constructed value if no such entry exists. ValueT lookup(const KeyT &Val) const { - return Map.lookup(Wrap(Val)); + typename MapT::const_iterator I = Map.find_as(Val); + return I != Map.end() ? I->second : ValueT(); } // Inserts key,value pair into the map if the key isn't already in the map. @@ -145,7 +146,12 @@ public: bool erase(const KeyT &Val) { - return Map.erase(Wrap(Val)); + typename MapT::iterator I = Map.find_as(Val); + if (I == Map.end()) + return false; + + Map.erase(I); + return true; } void erase(iterator I) { return Map.erase(I.base()); @@ -256,9 +262,15 @@ struct DenseMapInfo<ValueMapCallbackVH<KeyT, ValueT, Config> > { static unsigned getHashValue(const VH &Val) { return PointerInfo::getHashValue(Val.Unwrap()); } + static unsigned getHashValue(const KeyT &Val) { + return PointerInfo::getHashValue(Val); + } static bool isEqual(const VH &LHS, const VH &RHS) { return LHS == RHS; } + static bool isEqual(const KeyT &LHS, const VH &RHS) { + return LHS == RHS; + } }; |