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

Side by Side Diff: third_party/WebKit/Source/wtf/HashMap.h

Issue 2671933002: Migrate WTF::HashMap::add() to ::insert() (Closed)
Patch Set: Created 3 years, 10 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 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // pair of the iterator to the key location, and a boolean that's true if a 142 // pair of the iterator to the key location, and a boolean that's true if a
143 // new value was actually added 143 // new value was actually added
144 template <typename IncomingKeyType, typename IncomingMappedType> 144 template <typename IncomingKeyType, typename IncomingMappedType>
145 AddResult set(IncomingKeyType&&, IncomingMappedType&&); 145 AddResult set(IncomingKeyType&&, IncomingMappedType&&);
146 146
147 // does nothing if key is already present return value is a pair of the 147 // does nothing if key is already present return value is a pair of the
148 // iterator to the key location, and a boolean that's true if a new value 148 // iterator to the key location, and a boolean that's true if a new value
149 // was actually added 149 // was actually added
150 template <typename IncomingKeyType, typename IncomingMappedType> 150 template <typename IncomingKeyType, typename IncomingMappedType>
151 AddResult add(IncomingKeyType&&, IncomingMappedType&&); 151 AddResult add(IncomingKeyType&&, IncomingMappedType&&);
152 template <typename IncomingKeyType, typename IncomingMappedType>
153 AddResult insert(IncomingKeyType&&, IncomingMappedType&&);
152 154
153 void remove(KeyPeekInType); 155 void remove(KeyPeekInType);
154 void remove(iterator); 156 void remove(iterator);
155 void clear(); 157 void clear();
156 template <typename Collection> 158 template <typename Collection>
157 void removeAll(const Collection& toBeRemoved) { 159 void removeAll(const Collection& toBeRemoved) {
158 WTF::removeAll(*this, toBeRemoved); 160 WTF::removeAll(*this, toBeRemoved);
159 } 161 }
160 162
161 MappedType take(KeyPeekInType); // efficient combination of get with remove 163 MappedType take(KeyPeekInType); // efficient combination of get with remove
(...skipping 13 matching lines...) Expand all
175 // An alternate version of add() that finds the object by hashing and 177 // An alternate version of add() that finds the object by hashing and
176 // comparing with some other type, to avoid the cost of type conversion if 178 // comparing with some other type, to avoid the cost of type conversion if
177 // the object is already in the table. HashTranslator must have the 179 // the object is already in the table. HashTranslator must have the
178 // following function members: 180 // following function members:
179 // static unsigned hash(const T&); 181 // static unsigned hash(const T&);
180 // static bool equal(const ValueType&, const T&); 182 // static bool equal(const ValueType&, const T&);
181 // static translate(ValueType&, const T&, unsigned hashCode); 183 // static translate(ValueType&, const T&, unsigned hashCode);
182 template <typename HashTranslator, 184 template <typename HashTranslator,
183 typename IncomingKeyType, 185 typename IncomingKeyType,
184 typename IncomingMappedType> 186 typename IncomingMappedType>
185 AddResult add(IncomingKeyType&&, IncomingMappedType&&); 187 AddResult add(IncomingKeyType&&, IncomingMappedType&&);
haraken 2017/02/03 03:47:13 Shall we add a TODO that add() is deprecated?
188 template <typename HashTranslator,
189 typename IncomingKeyType,
190 typename IncomingMappedType>
191 AddResult insert(IncomingKeyType&&, IncomingMappedType&&);
186 192
187 static bool isValidKey(KeyPeekInType); 193 static bool isValidKey(KeyPeekInType);
188 194
189 template <typename VisitorDispatcher> 195 template <typename VisitorDispatcher>
190 void trace(VisitorDispatcher visitor) { 196 void trace(VisitorDispatcher visitor) {
191 m_impl.trace(visitor); 197 m_impl.trace(visitor);
192 } 198 }
193 199
194 private: 200 private:
195 template <typename IncomingKeyType, typename IncomingMappedType> 201 template <typename IncomingKeyType, typename IncomingMappedType>
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 template <typename T, 350 template <typename T,
345 typename U, 351 typename U,
346 typename V, 352 typename V,
347 typename W, 353 typename W,
348 typename X, 354 typename X,
349 typename Y> 355 typename Y>
350 HashMap<T, U, V, W, X, Y>::HashMap(std::initializer_list<ValueType> elements) { 356 HashMap<T, U, V, W, X, Y>::HashMap(std::initializer_list<ValueType> elements) {
351 if (elements.size()) 357 if (elements.size())
352 m_impl.reserveCapacityForSize(elements.size()); 358 m_impl.reserveCapacityForSize(elements.size());
353 for (const ValueType& element : elements) 359 for (const ValueType& element : elements)
354 add(element.key, element.value); 360 insert(element.key, element.value);
355 } 361 }
356 362
357 template <typename T, 363 template <typename T,
358 typename U, 364 typename U,
359 typename V, 365 typename V,
360 typename W, 366 typename W,
361 typename X, 367 typename X,
362 typename Y> 368 typename Y>
363 auto HashMap<T, U, V, W, X, Y>::operator=( 369 auto HashMap<T, U, V, W, X, Y>::operator=(
364 std::initializer_list<ValueType> elements) -> HashMap& { 370 std::initializer_list<ValueType> elements) -> HashMap& {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 std::forward<IncomingKeyType>(key), 574 std::forward<IncomingKeyType>(key),
569 std::forward<IncomingMappedType>(mapped)); 575 std::forward<IncomingMappedType>(mapped));
570 } 576 }
571 577
572 template <typename T, 578 template <typename T,
573 typename U, 579 typename U,
574 typename V, 580 typename V,
575 typename W, 581 typename W,
576 typename X, 582 typename X,
577 typename Y> 583 typename Y>
584 template <typename HashTranslator,
585 typename IncomingKeyType,
586 typename IncomingMappedType>
587 auto HashMap<T, U, V, W, X, Y>::insert(IncomingKeyType&& key,
588 IncomingMappedType&& mapped)
589 -> AddResult {
590 return m_impl.template addPassingHashCode<
591 HashMapTranslatorAdapter<ValueTraits, HashTranslator>>(
592 std::forward<IncomingKeyType>(key),
593 std::forward<IncomingMappedType>(mapped));
594 }
595
596 template <typename T,
597 typename U,
598 typename V,
599 typename W,
600 typename X,
601 typename Y>
578 template <typename IncomingKeyType, typename IncomingMappedType> 602 template <typename IncomingKeyType, typename IncomingMappedType>
579 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::add( 603 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::add(
580 IncomingKeyType&& key, 604 IncomingKeyType&& key,
581 IncomingMappedType&& mapped) { 605 IncomingMappedType&& mapped) {
582 return inlineAdd(std::forward<IncomingKeyType>(key), 606 return inlineAdd(std::forward<IncomingKeyType>(key),
583 std::forward<IncomingMappedType>(mapped)); 607 std::forward<IncomingMappedType>(mapped));
584 } 608 }
585 609
586 template <typename T, 610 template <typename T,
587 typename U, 611 typename U,
588 typename V, 612 typename V,
589 typename W, 613 typename W,
590 typename X, 614 typename X,
591 typename Y> 615 typename Y>
616 template <typename IncomingKeyType, typename IncomingMappedType>
617 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::insert(
618 IncomingKeyType&& key,
619 IncomingMappedType&& mapped) {
620 return inlineAdd(std::forward<IncomingKeyType>(key),
621 std::forward<IncomingMappedType>(mapped));
622 }
623
624 template <typename T,
625 typename U,
626 typename V,
627 typename W,
628 typename X,
629 typename Y>
592 typename HashMap<T, U, V, W, X, Y>::MappedPeekType 630 typename HashMap<T, U, V, W, X, Y>::MappedPeekType
593 HashMap<T, U, V, W, X, Y>::get(KeyPeekInType key) const { 631 HashMap<T, U, V, W, X, Y>::get(KeyPeekInType key) const {
594 ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key); 632 ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key);
595 if (!entry) 633 if (!entry)
596 return MappedTraits::peek(MappedTraits::emptyValue()); 634 return MappedTraits::peek(MappedTraits::emptyValue());
597 return MappedTraits::peek(entry->value); 635 return MappedTraits::peek(entry->value);
598 } 636 }
599 637
600 template <typename T, 638 template <typename T,
601 typename U, 639 typename U,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 iterator end = collection.end().values(); 774 iterator end = collection.end().values();
737 for (unsigned i = 0; it != end; ++it, ++i) 775 for (unsigned i = 0; it != end; ++it, ++i)
738 vector[i] = *it; 776 vector[i] = *it;
739 } 777 }
740 778
741 } // namespace WTF 779 } // namespace WTF
742 780
743 using WTF::HashMap; 781 using WTF::HashMap;
744 782
745 #endif // WTF_HashMap_h 783 #endif // WTF_HashMap_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/HashCountedSet.h ('k') | third_party/WebKit/Source/wtf/HashMapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698