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

Unified Diff: Source/wtf/HashTable.h

Issue 1176303008: Avoid argument copying in WTF hash-based containers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix NRVO in test key traits on Win Created 5 years, 5 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
« Source/wtf/HashMapTest.cpp ('K') | « Source/wtf/HashMapTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/HashTable.h
diff --git a/Source/wtf/HashTable.h b/Source/wtf/HashTable.h
index 8590a00335d47f69d53a715274e33aaeca3efe6c..c1f457922f7a92e6dde4d5a7f4cdcdeb4bda9d03 100644
--- a/Source/wtf/HashTable.h
+++ b/Source/wtf/HashTable.h
@@ -441,13 +441,13 @@ namespace WTF {
template<typename HashTranslator, typename T, typename Extra> AddResult add(const T& key, const Extra&);
template<typename HashTranslator, typename T, typename Extra> AddResult addPassingHashCode(const T& key, const Extra&);
- iterator find(KeyPeekInType key) { return find<IdentityTranslatorType>(key); }
- const_iterator find(KeyPeekInType key) const { return find<IdentityTranslatorType>(key); }
- bool contains(KeyPeekInType key) const { return contains<IdentityTranslatorType>(key); }
+ iterator find(KeyPeekInType);
+ const_iterator find(KeyPeekInType) const;
+ bool contains(KeyPeekInType key) const { return lookup(key); }
template<typename HashTranslator, typename T> iterator find(const T&);
template<typename HashTranslator, typename T> const_iterator find(const T&) const;
- template<typename HashTranslator, typename T> bool contains(const T&) const;
+ template<typename HashTranslator, typename T> bool contains(const T& key) const { return lookup<HashTranslator>(key); }
void remove(KeyPeekInType);
void remove(iterator);
@@ -459,6 +459,7 @@ namespace WTF {
static bool isEmptyOrDeletedBucket(const ValueType& value) { return HashTableHelper<ValueType, Extractor, KeyTraits>:: isEmptyOrDeletedBucket(value); }
ValueType* lookup(KeyPeekInType key) { return lookup<IdentityTranslatorType, KeyPeekInType>(key); }
+ const ValueType* lookup(KeyPeekInType key) const { return lookup<IdentityTranslatorType, KeyPeekInType>(key); }
template<typename HashTranslator, typename T> ValueType* lookup(T);
template<typename HashTranslator, typename T> const ValueType* lookup(T) const;
@@ -898,6 +899,20 @@ namespace WTF {
}
template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
+ inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::find(KeyPeekInType key) -> iterator {
+ if (ValueType* entry = lookup(key))
+ return makeKnownGoodIterator(entry);
+ return end();
+ }
+
+ template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
+ inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::find(KeyPeekInType key) const -> const_iterator {
+ if (ValueType* entry = const_cast<HashTable*>(this)->lookup(key))
+ return makeKnownGoodConstIterator(entry);
+ return end();
+ }
+
+ template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
template <typename HashTranslator, typename T>
inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::iterator HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::find(const T& key)
{
@@ -920,13 +935,6 @@ namespace WTF {
}
template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
- template <typename HashTranslator, typename T>
- bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::contains(const T& key) const
- {
- return const_cast<HashTable*>(this)->lookup<HashTranslator>(key);
- }
-
- template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits, typename Allocator>
void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::remove(ValueType* pos)
{
registerModification();
« Source/wtf/HashMapTest.cpp ('K') | « Source/wtf/HashMapTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698