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

Side by Side Diff: Source/wtf/HashTable.h

Issue 117123003: Inline HashTable::find() methods for performance (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove other unnecessary null check Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 key ^= (key >> 7); 444 key ^= (key >> 7);
445 key ^= (key << 2); 445 key ^= (key << 2);
446 key ^= (key >> 20); 446 key ^= (key >> 20);
447 return key; 447 return key;
448 } 448 }
449 449
450 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 450 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
451 template<typename HashTranslator, typename T> 451 template<typename HashTranslator, typename T>
452 inline Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTra its, Allocator>::lookup(const T& key) 452 inline Value* HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTra its, Allocator>::lookup(const T& key)
453 { 453 {
454 ValueType* table = m_table;
455 if (!table)
456 return 0;
457
454 int k = 0; 458 int k = 0;
455 int sizeMask = m_tableSizeMask; 459 int sizeMask = m_tableSizeMask;
456 ValueType* table = m_table;
457 unsigned h = HashTranslator::hash(key); 460 unsigned h = HashTranslator::hash(key);
458 int i = h & sizeMask; 461 int i = h & sizeMask;
459 462
460 if (!table)
461 return 0;
462
463 #if DUMP_HASHTABLE_STATS 463 #if DUMP_HASHTABLE_STATS
464 atomicIncrement(&HashTableStats::numAccesses); 464 atomicIncrement(&HashTableStats::numAccesses);
465 int probeCount = 0; 465 int probeCount = 0;
466 #endif 466 #endif
467 467
468 #if DUMP_HASHTABLE_STATS_PER_TABLE 468 #if DUMP_HASHTABLE_STATS_PER_TABLE
469 ++m_stats->numAccesses; 469 ++m_stats->numAccesses;
470 int perTableProbeCount = 0; 470 int perTableProbeCount = 0;
471 #endif 471 #endif
472 472
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 #endif 788 #endif
789 #if DUMP_HASHTABLE_STATS_PER_TABLE 789 #if DUMP_HASHTABLE_STATS_PER_TABLE
790 ++m_stats->numReinserts; 790 ++m_stats->numReinserts;
791 #endif 791 #endif
792 792
793 Mover<ValueType, Traits::needsDestruction>::move(entry, *lookupForWritin g(Extractor::extract(entry)).first); 793 Mover<ValueType, Traits::needsDestruction>::move(entry, *lookupForWritin g(Extractor::extract(entry)).first);
794 } 794 }
795 795
796 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 796 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
797 template <typename HashTranslator, typename T> 797 template <typename HashTranslator, typename T>
798 typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::iterator HashTable<Key, Value, Extractor, HashFunctions, Traits, Key Traits, Allocator>::find(const T& key) 798 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)
799 { 799 {
800 if (!m_table)
801 return end();
802
803 ValueType* entry = lookup<HashTranslator>(key); 800 ValueType* entry = lookup<HashTranslator>(key);
804 if (!entry) 801 if (!entry)
805 return end(); 802 return end();
806 803
807 return makeKnownGoodIterator(entry); 804 return makeKnownGoodIterator(entry);
808 } 805 }
809 806
810 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 807 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
811 template <typename HashTranslator, typename T> 808 template <typename HashTranslator, typename T>
812 typename HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::const_iterator HashTable<Key, Value, Extractor, HashFunctions, Trait s, KeyTraits, Allocator>::find(const T& key) const 809 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
813 { 810 {
814 if (!m_table)
815 return end();
816
817 ValueType* entry = const_cast<HashTable*>(this)->lookup<HashTranslator>( key); 811 ValueType* entry = const_cast<HashTable*>(this)->lookup<HashTranslator>( key);
818 if (!entry) 812 if (!entry)
819 return end(); 813 return end();
820 814
821 return makeKnownGoodConstIterator(entry); 815 return makeKnownGoodConstIterator(entry);
822 } 816 }
823 817
824 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 818 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
825 template <typename HashTranslator, typename T> 819 template <typename HashTranslator, typename T>
826 bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::contains(const T& key) const 820 bool HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::contains(const T& key) const
827 { 821 {
828 if (!m_table)
829 return false;
830
831 return const_cast<HashTable*>(this)->lookup<HashTranslator>(key); 822 return const_cast<HashTable*>(this)->lookup<HashTranslator>(key);
832 } 823 }
833 824
834 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator> 825 template<typename Key, typename Value, typename Extractor, typename HashFunc tions, typename Traits, typename KeyTraits, typename Allocator>
835 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::remove(ValueType* pos) 826 void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allo cator>::remove(ValueType* pos)
836 { 827 {
837 #if DUMP_HASHTABLE_STATS 828 #if DUMP_HASHTABLE_STATS
838 atomicIncrement(&HashTableStats::numRemoves); 829 atomicIncrement(&HashTableStats::numRemoves);
839 #endif 830 #endif
840 #if DUMP_HASHTABLE_STATS_PER_TABLE 831 #if DUMP_HASHTABLE_STATS_PER_TABLE
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 inline bool operator!=(const HashTableIteratorAdapter<T, U>& a, const HashTa bleConstIteratorAdapter<T, U>& b) 1093 inline bool operator!=(const HashTableIteratorAdapter<T, U>& a, const HashTa bleConstIteratorAdapter<T, U>& b)
1103 { 1094 {
1104 return a.m_impl != b.m_impl; 1095 return a.m_impl != b.m_impl;
1105 } 1096 }
1106 1097
1107 } // namespace WTF 1098 } // namespace WTF
1108 1099
1109 #include "wtf/HashIterators.h" 1100 #include "wtf/HashIterators.h"
1110 1101
1111 #endif // WTF_HashTable_h 1102 #endif // WTF_HashTable_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698