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

Side by Side 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, 4 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 unified diff | Download patch
« Source/wtf/HashMapTest.cpp ('K') | « Source/wtf/HashMapTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008 David Levin <levin@chromium.org> 3 * Copyright (C) 2008 David Levin <levin@chromium.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 { 434 {
435 return add<IdentityTranslatorType>(Extractor::extract(value), value) ; 435 return add<IdentityTranslatorType>(Extractor::extract(value), value) ;
436 } 436 }
437 437
438 // A special version of add() that finds the object by hashing and compa ring 438 // A special version of add() that finds the object by hashing and compa ring
439 // with some other type, to avoid the cost of type conversion if the obj ect is already 439 // with some other type, to avoid the cost of type conversion if the obj ect is already
440 // in the table. 440 // in the table.
441 template<typename HashTranslator, typename T, typename Extra> AddResult add(const T& key, const Extra&); 441 template<typename HashTranslator, typename T, typename Extra> AddResult add(const T& key, const Extra&);
442 template<typename HashTranslator, typename T, typename Extra> AddResult addPassingHashCode(const T& key, const Extra&); 442 template<typename HashTranslator, typename T, typename Extra> AddResult addPassingHashCode(const T& key, const Extra&);
443 443
444 iterator find(KeyPeekInType key) { return find<IdentityTranslatorType>(k ey); } 444 iterator find(KeyPeekInType);
445 const_iterator find(KeyPeekInType key) const { return find<IdentityTrans latorType>(key); } 445 const_iterator find(KeyPeekInType) const;
446 bool contains(KeyPeekInType key) const { return contains<IdentityTransla torType>(key); } 446 bool contains(KeyPeekInType key) const { return lookup(key); }
447 447
448 template<typename HashTranslator, typename T> iterator find(const T&); 448 template<typename HashTranslator, typename T> iterator find(const T&);
449 template<typename HashTranslator, typename T> const_iterator find(const T&) const; 449 template<typename HashTranslator, typename T> const_iterator find(const T&) const;
450 template<typename HashTranslator, typename T> bool contains(const T&) co nst; 450 template<typename HashTranslator, typename T> bool contains(const T& key ) const { return lookup<HashTranslator>(key); }
451 451
452 void remove(KeyPeekInType); 452 void remove(KeyPeekInType);
453 void remove(iterator); 453 void remove(iterator);
454 void remove(const_iterator); 454 void remove(const_iterator);
455 void clear(); 455 void clear();
456 456
457 static bool isEmptyBucket(const ValueType& value) { return isHashTraitsE mptyValue<KeyTraits>(Extractor::extract(value)); } 457 static bool isEmptyBucket(const ValueType& value) { return isHashTraitsE mptyValue<KeyTraits>(Extractor::extract(value)); }
458 static bool isDeletedBucket(const ValueType& value) { return KeyTraits:: isDeletedValue(Extractor::extract(value)); } 458 static bool isDeletedBucket(const ValueType& value) { return KeyTraits:: isDeletedValue(Extractor::extract(value)); }
459 static bool isEmptyOrDeletedBucket(const ValueType& value) { return Hash TableHelper<ValueType, Extractor, KeyTraits>:: isEmptyOrDeletedBucket(value); } 459 static bool isEmptyOrDeletedBucket(const ValueType& value) { return Hash TableHelper<ValueType, Extractor, KeyTraits>:: isEmptyOrDeletedBucket(value); }
460 460
461 ValueType* lookup(KeyPeekInType key) { return lookup<IdentityTranslatorT ype, KeyPeekInType>(key); } 461 ValueType* lookup(KeyPeekInType key) { return lookup<IdentityTranslatorT ype, KeyPeekInType>(key); }
462 const ValueType* lookup(KeyPeekInType key) const { return lookup<Identit yTranslatorType, KeyPeekInType>(key); }
462 template<typename HashTranslator, typename T> ValueType* lookup(T); 463 template<typename HashTranslator, typename T> ValueType* lookup(T);
463 template<typename HashTranslator, typename T> const ValueType* lookup(T) const; 464 template<typename HashTranslator, typename T> const ValueType* lookup(T) const;
464 465
465 typedef int HasInlinedTraceMethodMarker; 466 typedef int HasInlinedTraceMethodMarker;
466 template<typename VisitorDispatcher> void trace(VisitorDispatcher); 467 template<typename VisitorDispatcher> void trace(VisitorDispatcher);
467 468
468 #if ENABLE(ASSERT) 469 #if ENABLE(ASSERT)
469 int64_t modifications() const { return m_modifications; } 470 int64_t modifications() const { return m_modifications; }
470 void registerModification() { m_modifications++; } 471 void registerModification() { m_modifications++; }
471 // HashTable and collections that build on it do not support 472 // HashTable and collections that build on it do not support
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 #if DUMP_HASHTABLE_STATS_PER_TABLE 892 #if DUMP_HASHTABLE_STATS_PER_TABLE
892 ++m_stats->numReinserts; 893 ++m_stats->numReinserts;
893 #endif 894 #endif
894 Value* newEntry = lookupForWriting(Extractor::extract(entry)).first; 895 Value* newEntry = lookupForWriting(Extractor::extract(entry)).first;
895 Mover<ValueType, Allocator>::move(entry, *newEntry); 896 Mover<ValueType, Allocator>::move(entry, *newEntry);
896 897
897 return newEntry; 898 return newEntry;
898 } 899 }
899 900
900 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 901 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
902 inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTrait s, Allocator>::find(KeyPeekInType key) -> iterator {
903 if (ValueType* entry = lookup(key))
904 return makeKnownGoodIterator(entry);
905 return end();
906 }
907
908 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
909 inline auto HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTrait s, Allocator>::find(KeyPeekInType key) const -> const_iterator {
910 if (ValueType* entry = const_cast<HashTable*>(this)->lookup(key))
911 return makeKnownGoodConstIterator(entry);
912 return end();
913 }
914
915 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
901 template <typename HashTranslator, typename T> 916 template <typename HashTranslator, typename T>
902 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT raits, Allocator>::iterator HashTable<Key, Value, Extractor, HashFunctions, Trai ts, KeyTraits, Allocator>::find(const T& key) 917 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT raits, Allocator>::iterator HashTable<Key, Value, Extractor, HashFunctions, Trai ts, KeyTraits, Allocator>::find(const T& key)
903 { 918 {
904 ValueType* entry = lookup<HashTranslator>(key); 919 ValueType* entry = lookup<HashTranslator>(key);
905 if (!entry) 920 if (!entry)
906 return end(); 921 return end();
907 922
908 return makeKnownGoodIterator(entry); 923 return makeKnownGoodIterator(entry);
909 } 924 }
910 925
911 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 926 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
912 template <typename HashTranslator, typename T> 927 template <typename HashTranslator, typename T>
913 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT raits, Allocator>::const_iterator HashTable<Key, Value, Extractor, HashFunctions , Traits, KeyTraits, Allocator>::find(const T& key) const 928 inline typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyT raits, Allocator>::const_iterator HashTable<Key, Value, Extractor, HashFunctions , Traits, KeyTraits, Allocator>::find(const T& key) const
914 { 929 {
915 ValueType* entry = const_cast<HashTable*>(this)->lookup<HashTranslator>( key); 930 ValueType* entry = const_cast<HashTable*>(this)->lookup<HashTranslator>( key);
916 if (!entry) 931 if (!entry)
917 return end(); 932 return end();
918 933
919 return makeKnownGoodConstIterator(entry); 934 return makeKnownGoodConstIterator(entry);
920 } 935 }
921 936
922 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 937 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
923 template <typename HashTranslator, typename T>
924 bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::contains(const T& key) const
925 {
926 return const_cast<HashTable*>(this)->lookup<HashTranslator>(key);
927 }
928
929 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
930 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::remove(ValueType* pos) 938 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::remove(ValueType* pos)
931 { 939 {
932 registerModification(); 940 registerModification();
933 #if DUMP_HASHTABLE_STATS 941 #if DUMP_HASHTABLE_STATS
934 atomicIncrement(&HashTableStats::numRemoves); 942 atomicIncrement(&HashTableStats::numRemoves);
935 #endif 943 #endif
936 #if DUMP_HASHTABLE_STATS_PER_TABLE 944 #if DUMP_HASHTABLE_STATS_PER_TABLE
937 ++m_stats->numRemoves; 945 ++m_stats->numRemoves;
938 #endif 946 #endif
939 947
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 CollectionIterator end(toBeRemoved.end()); 1449 CollectionIterator end(toBeRemoved.end());
1442 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) 1450 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it)
1443 collection.remove(*it); 1451 collection.remove(*it);
1444 } 1452 }
1445 1453
1446 } // namespace WTF 1454 } // namespace WTF
1447 1455
1448 #include "wtf/HashIterators.h" 1456 #include "wtf/HashIterators.h"
1449 1457
1450 #endif // WTF_HashTable_h 1458 #endif // WTF_HashTable_h
OLDNEW
« 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