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

Side by Side Diff: third_party/WebKit/Source/platform/wtf/HashTable.h

Issue 2804953004: Migrate WTF::HashTable::add() to ::insert() (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2008 David Levin <levin@chromium.org> 4 * Copyright (C) 2008 David Levin <levin@chromium.org>
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 return m_tableSize; 722 return m_tableSize;
723 } 723 }
724 bool isEmpty() const { 724 bool isEmpty() const {
725 DCHECK(!accessForbidden()); 725 DCHECK(!accessForbidden());
726 return !m_keyCount; 726 return !m_keyCount;
727 } 727 }
728 728
729 void reserveCapacityForSize(unsigned size); 729 void reserveCapacityForSize(unsigned size);
730 730
731 template <typename IncomingValueType> 731 template <typename IncomingValueType>
732 AddResult add(IncomingValueType&& value) { 732 AddResult insert(IncomingValueType&& value) {
733 return add<IdentityTranslatorType>(Extractor::extract(value), 733 return insert<IdentityTranslatorType>(
734 std::forward<IncomingValueType>(value)); 734 Extractor::extract(value), std::forward<IncomingValueType>(value));
735 } 735 }
736 736
737 // A special version of add() that finds the object by hashing and comparing 737 // A special version of insert() that finds the object by hashing and
738 // with some other type, to avoid the cost of type conversion if the object 738 // comparing with some other type, to avoid the cost of type conversion if the
739 // is already in the table. 739 // object is already in the table.
740 template <typename HashTranslator, typename T, typename Extra> 740 template <typename HashTranslator, typename T, typename Extra>
741 AddResult add(T&& key, Extra&&); 741 AddResult insert(T&& key, Extra&&);
742 template <typename HashTranslator, typename T, typename Extra> 742 template <typename HashTranslator, typename T, typename Extra>
743 AddResult addPassingHashCode(T&& key, Extra&&); 743 AddResult insertPassingHashCode(T&& key, Extra&&);
744 744
745 iterator find(KeyPeekInType key) { return find<IdentityTranslatorType>(key); } 745 iterator find(KeyPeekInType key) { return find<IdentityTranslatorType>(key); }
746 const_iterator find(KeyPeekInType key) const { 746 const_iterator find(KeyPeekInType key) const {
747 return find<IdentityTranslatorType>(key); 747 return find<IdentityTranslatorType>(key);
748 } 748 }
749 bool contains(KeyPeekInType key) const { 749 bool contains(KeyPeekInType key) const {
750 return contains<IdentityTranslatorType>(key); 750 return contains<IdentityTranslatorType>(key);
751 } 751 }
752 752
753 template <typename HashTranslator, typename T> 753 template <typename HashTranslator, typename T>
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 typename Allocator> 1222 typename Allocator>
1223 template <typename HashTranslator, typename T, typename Extra> 1223 template <typename HashTranslator, typename T, typename Extra>
1224 typename HashTable<Key, 1224 typename HashTable<Key,
1225 Value, 1225 Value,
1226 Extractor, 1226 Extractor,
1227 HashFunctions, 1227 HashFunctions,
1228 Traits, 1228 Traits,
1229 KeyTraits, 1229 KeyTraits,
1230 Allocator>::AddResult 1230 Allocator>::AddResult
1231 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>:: 1231 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::
1232 add(T&& key, Extra&& extra) { 1232 insert(T&& key, Extra&& extra) {
1233 DCHECK(!accessForbidden()); 1233 DCHECK(!accessForbidden());
1234 DCHECK(Allocator::isAllocationAllowed()); 1234 DCHECK(Allocator::isAllocationAllowed());
1235 if (!m_table) 1235 if (!m_table)
1236 expand(); 1236 expand();
1237 1237
1238 DCHECK(m_table); 1238 DCHECK(m_table);
1239 1239
1240 ValueType* table = m_table; 1240 ValueType* table = m_table;
1241 size_t k = 0; 1241 size_t k = 0;
1242 size_t sizeMask = tableSizeMask(); 1242 size_t sizeMask = tableSizeMask();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 typename Allocator> 1318 typename Allocator>
1319 template <typename HashTranslator, typename T, typename Extra> 1319 template <typename HashTranslator, typename T, typename Extra>
1320 typename HashTable<Key, 1320 typename HashTable<Key,
1321 Value, 1321 Value,
1322 Extractor, 1322 Extractor,
1323 HashFunctions, 1323 HashFunctions,
1324 Traits, 1324 Traits,
1325 KeyTraits, 1325 KeyTraits,
1326 Allocator>::AddResult 1326 Allocator>::AddResult
1327 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>:: 1327 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::
1328 addPassingHashCode(T&& key, Extra&& extra) { 1328 insertPassingHashCode(T&& key, Extra&& extra) {
1329 DCHECK(!accessForbidden()); 1329 DCHECK(!accessForbidden());
1330 DCHECK(Allocator::isAllocationAllowed()); 1330 DCHECK(Allocator::isAllocationAllowed());
1331 if (!m_table) 1331 if (!m_table)
1332 expand(); 1332 expand();
1333 1333
1334 FullLookupType lookupResult = fullLookupForWriting<HashTranslator>(key); 1334 FullLookupType lookupResult = fullLookupForWriting<HashTranslator>(key);
1335 1335
1336 ValueType* entry = lookupResult.first.first; 1336 ValueType* entry = lookupResult.first.first;
1337 bool found = lookupResult.first.second; 1337 bool found = lookupResult.first.second;
1338 unsigned h = lookupResult.second; 1338 unsigned h = lookupResult.second;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1826 , 1826 ,
1827 m_stats(HashTableStatsPtr<Allocator>::copy(other.m_stats)) 1827 m_stats(HashTableStatsPtr<Allocator>::copy(other.m_stats))
1828 #endif 1828 #endif
1829 { 1829 {
1830 if (other.size()) 1830 if (other.size())
1831 reserveCapacityForSize(other.size()); 1831 reserveCapacityForSize(other.size());
1832 // Copy the hash table the dumb way, by adding each element to the new 1832 // Copy the hash table the dumb way, by adding each element to the new
1833 // table. It might be more efficient to copy the table slots, but it's not 1833 // table. It might be more efficient to copy the table slots, but it's not
1834 // clear that efficiency is needed. 1834 // clear that efficiency is needed.
1835 for (const auto& element : other) 1835 for (const auto& element : other)
1836 add(element); 1836 insert(element);
1837 } 1837 }
1838 1838
1839 template <typename Key, 1839 template <typename Key,
1840 typename Value, 1840 typename Value,
1841 typename Extractor, 1841 typename Extractor,
1842 typename HashFunctions, 1842 typename HashFunctions,
1843 typename Traits, 1843 typename Traits,
1844 typename KeyTraits, 1844 typename KeyTraits,
1845 typename Allocator> 1845 typename Allocator>
1846 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>:: 1846 HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits, Allocator>::
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 CollectionIterator end(toBeRemoved.end()); 2271 CollectionIterator end(toBeRemoved.end());
2272 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it) 2272 for (CollectionIterator it(toBeRemoved.begin()); it != end; ++it)
2273 collection.erase(*it); 2273 collection.erase(*it);
2274 } 2274 }
2275 2275
2276 } // namespace WTF 2276 } // namespace WTF
2277 2277
2278 #include "wtf/HashIterators.h" 2278 #include "wtf/HashIterators.h"
2279 2279
2280 #endif // WTF_HashTable_h 2280 #endif // WTF_HashTable_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/wtf/HashSet.h ('k') | third_party/WebKit/Source/platform/wtf/LinkedHashSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698