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

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

Issue 2671933002: Migrate WTF::HashMap::add() to ::insert() (Closed)
Patch Set: rebase, add TODOs 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 // replaces value but not key if key is already present return value is a 141 // replaces value but not key if key is already present return value is a
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 // TODO(pilgrim) remove deprecated add() method, use insert() instead
151 // https://crbug.com/662431
150 template <typename IncomingKeyType, typename IncomingMappedType> 152 template <typename IncomingKeyType, typename IncomingMappedType>
151 AddResult add(IncomingKeyType&&, IncomingMappedType&&); 153 AddResult add(IncomingKeyType&&, IncomingMappedType&&);
154 template <typename IncomingKeyType, typename IncomingMappedType>
155 AddResult insert(IncomingKeyType&&, IncomingMappedType&&);
152 156
153 // TODO(pilgrim) remove remove() method once all references migrated to 157 // TODO(pilgrim) remove remove() method once all references migrated to
154 // erase() 158 // erase()
155 // https://crbug.com/662431 159 // https://crbug.com/662431
156 void remove(KeyPeekInType); 160 void remove(KeyPeekInType);
157 void erase(KeyPeekInType); 161 void erase(KeyPeekInType);
158 void remove(iterator); 162 void remove(iterator);
159 void clear(); 163 void clear();
160 template <typename Collection> 164 template <typename Collection>
161 void removeAll(const Collection& toBeRemoved) { 165 void removeAll(const Collection& toBeRemoved) {
(...skipping 14 matching lines...) Expand all
176 template <typename HashTranslator, typename T> 180 template <typename HashTranslator, typename T>
177 bool contains(const T&) const; 181 bool contains(const T&) const;
178 182
179 // An alternate version of add() that finds the object by hashing and 183 // An alternate version of add() that finds the object by hashing and
180 // comparing with some other type, to avoid the cost of type conversion if 184 // comparing with some other type, to avoid the cost of type conversion if
181 // the object is already in the table. HashTranslator must have the 185 // the object is already in the table. HashTranslator must have the
182 // following function members: 186 // following function members:
183 // static unsigned hash(const T&); 187 // static unsigned hash(const T&);
184 // static bool equal(const ValueType&, const T&); 188 // static bool equal(const ValueType&, const T&);
185 // static translate(ValueType&, const T&, unsigned hashCode); 189 // static translate(ValueType&, const T&, unsigned hashCode);
190 // TODO(pilgrim) remove deprecated add() method, use insert() instead
191 // https://crbug.com/662431
186 template <typename HashTranslator, 192 template <typename HashTranslator,
187 typename IncomingKeyType, 193 typename IncomingKeyType,
188 typename IncomingMappedType> 194 typename IncomingMappedType>
189 AddResult add(IncomingKeyType&&, IncomingMappedType&&); 195 AddResult add(IncomingKeyType&&, IncomingMappedType&&);
196 template <typename HashTranslator,
197 typename IncomingKeyType,
198 typename IncomingMappedType>
199 AddResult insert(IncomingKeyType&&, IncomingMappedType&&);
190 200
191 static bool isValidKey(KeyPeekInType); 201 static bool isValidKey(KeyPeekInType);
192 202
193 template <typename VisitorDispatcher> 203 template <typename VisitorDispatcher>
194 void trace(VisitorDispatcher visitor) { 204 void trace(VisitorDispatcher visitor) {
195 m_impl.trace(visitor); 205 m_impl.trace(visitor);
196 } 206 }
197 207
198 private: 208 private:
199 template <typename IncomingKeyType, typename IncomingMappedType> 209 template <typename IncomingKeyType, typename IncomingMappedType>
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 template <typename T, 358 template <typename T,
349 typename U, 359 typename U,
350 typename V, 360 typename V,
351 typename W, 361 typename W,
352 typename X, 362 typename X,
353 typename Y> 363 typename Y>
354 HashMap<T, U, V, W, X, Y>::HashMap(std::initializer_list<ValueType> elements) { 364 HashMap<T, U, V, W, X, Y>::HashMap(std::initializer_list<ValueType> elements) {
355 if (elements.size()) 365 if (elements.size())
356 m_impl.reserveCapacityForSize(elements.size()); 366 m_impl.reserveCapacityForSize(elements.size());
357 for (const ValueType& element : elements) 367 for (const ValueType& element : elements)
358 add(element.key, element.value); 368 insert(element.key, element.value);
359 } 369 }
360 370
361 template <typename T, 371 template <typename T,
362 typename U, 372 typename U,
363 typename V, 373 typename V,
364 typename W, 374 typename W,
365 typename X, 375 typename X,
366 typename Y> 376 typename Y>
367 auto HashMap<T, U, V, W, X, Y>::operator=( 377 auto HashMap<T, U, V, W, X, Y>::operator=(
368 std::initializer_list<ValueType> elements) -> HashMap& { 378 std::initializer_list<ValueType> elements) -> HashMap& {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 std::forward<IncomingKeyType>(key), 582 std::forward<IncomingKeyType>(key),
573 std::forward<IncomingMappedType>(mapped)); 583 std::forward<IncomingMappedType>(mapped));
574 } 584 }
575 585
576 template <typename T, 586 template <typename T,
577 typename U, 587 typename U,
578 typename V, 588 typename V,
579 typename W, 589 typename W,
580 typename X, 590 typename X,
581 typename Y> 591 typename Y>
592 template <typename HashTranslator,
593 typename IncomingKeyType,
594 typename IncomingMappedType>
595 auto HashMap<T, U, V, W, X, Y>::insert(IncomingKeyType&& key,
596 IncomingMappedType&& mapped)
597 -> AddResult {
598 return m_impl.template addPassingHashCode<
599 HashMapTranslatorAdapter<ValueTraits, HashTranslator>>(
600 std::forward<IncomingKeyType>(key),
601 std::forward<IncomingMappedType>(mapped));
602 }
603
604 template <typename T,
605 typename U,
606 typename V,
607 typename W,
608 typename X,
609 typename Y>
582 template <typename IncomingKeyType, typename IncomingMappedType> 610 template <typename IncomingKeyType, typename IncomingMappedType>
583 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::add( 611 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::add(
584 IncomingKeyType&& key, 612 IncomingKeyType&& key,
585 IncomingMappedType&& mapped) { 613 IncomingMappedType&& mapped) {
586 return inlineAdd(std::forward<IncomingKeyType>(key), 614 return inlineAdd(std::forward<IncomingKeyType>(key),
587 std::forward<IncomingMappedType>(mapped)); 615 std::forward<IncomingMappedType>(mapped));
588 } 616 }
589 617
590 template <typename T, 618 template <typename T,
591 typename U, 619 typename U,
592 typename V, 620 typename V,
593 typename W, 621 typename W,
594 typename X, 622 typename X,
595 typename Y> 623 typename Y>
624 template <typename IncomingKeyType, typename IncomingMappedType>
625 typename HashMap<T, U, V, W, X, Y>::AddResult HashMap<T, U, V, W, X, Y>::insert(
626 IncomingKeyType&& key,
627 IncomingMappedType&& mapped) {
628 return inlineAdd(std::forward<IncomingKeyType>(key),
629 std::forward<IncomingMappedType>(mapped));
630 }
631
632 template <typename T,
633 typename U,
634 typename V,
635 typename W,
636 typename X,
637 typename Y>
596 typename HashMap<T, U, V, W, X, Y>::MappedPeekType 638 typename HashMap<T, U, V, W, X, Y>::MappedPeekType
597 HashMap<T, U, V, W, X, Y>::get(KeyPeekInType key) const { 639 HashMap<T, U, V, W, X, Y>::get(KeyPeekInType key) const {
598 ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key); 640 ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key);
599 if (!entry) 641 if (!entry)
600 return MappedTraits::peek(MappedTraits::emptyValue()); 642 return MappedTraits::peek(MappedTraits::emptyValue());
601 return MappedTraits::peek(entry->value); 643 return MappedTraits::peek(entry->value);
602 } 644 }
603 645
604 template <typename T, 646 template <typename T,
605 typename U, 647 typename U,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 iterator end = collection.end().values(); 792 iterator end = collection.end().values();
751 for (unsigned i = 0; it != end; ++it, ++i) 793 for (unsigned i = 0; it != end; ++it, ++i)
752 vector[i] = *it; 794 vector[i] = *it;
753 } 795 }
754 796
755 } // namespace WTF 797 } // namespace WTF
756 798
757 using WTF::HashMap; 799 using WTF::HashMap;
758 800
759 #endif // WTF_HashMap_h 801 #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