Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 template <typename ValueTraits, typename HashFunctions> | 247 template <typename ValueTraits, typename HashFunctions> |
| 248 struct HashMapTranslator { | 248 struct HashMapTranslator { |
| 249 STATIC_ONLY(HashMapTranslator); | 249 STATIC_ONLY(HashMapTranslator); |
| 250 template <typename T> static unsigned hash(const T& key) { return HashFuncti ons::hash(key); } | 250 template <typename T> static unsigned hash(const T& key) { return HashFuncti ons::hash(key); } |
| 251 template <typename T, typename U> static bool equal(const T& a, const U& b) { return HashFunctions::equal(a, b); } | 251 template <typename T, typename U> static bool equal(const T& a, const U& b) { return HashFunctions::equal(a, b); } |
| 252 template <typename T, typename U, typename V> static void translate(T& locat ion, U&& key, V&& mapped) | 252 template <typename T, typename U, typename V> static void translate(T& locat ion, U&& key, V&& mapped) |
| 253 { | 253 { |
| 254 location.key = std::forward<U>(key); | 254 location.key = std::forward<U>(key); |
| 255 ValueTraits::ValueTraits::store(std::forward<V>(mapped), location.value) ; | 255 ValueTraits::ValueTraits::store(std::move(std::forward<V>(mapped)), loca tion.value); |
|
Yuta Kitamura
2016/09/05 06:46:09
Nesting std::move and std::forward does not make s
Bugs Nash
2016/09/14 05:23:29
Done
| |
| 256 } | 256 } |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 template <typename ValueTraits, typename Translator> | 259 template <typename ValueTraits, typename Translator> |
| 260 struct HashMapTranslatorAdapter { | 260 struct HashMapTranslatorAdapter { |
| 261 STATIC_ONLY(HashMapTranslatorAdapter); | 261 STATIC_ONLY(HashMapTranslatorAdapter); |
| 262 template <typename T> static unsigned hash(const T& key) { return Translator ::hash(key); } | 262 template <typename T> static unsigned hash(const T& key) { return Translator ::hash(key); } |
| 263 template <typename T, typename U> static bool equal(const T& a, const U& b) { return Translator::equal(a, b); } | 263 template <typename T, typename U> static bool equal(const T& a, const U& b) { return Translator::equal(a, b); } |
| 264 template <typename T, typename U, typename V> static void translate(T& locat ion, U&& key, V&& mapped, unsigned hashCode) | 264 template <typename T, typename U, typename V> static void translate(T& locat ion, U&& key, V&& mapped, unsigned hashCode) |
| 265 { | 265 { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 template <typename IncomingKeyType, typename IncomingMappedType> | 364 template <typename IncomingKeyType, typename IncomingMappedType> |
| 365 typename HashMap<T, U, V, W, X, Y>::AddResult | 365 typename HashMap<T, U, V, W, X, Y>::AddResult |
| 366 HashMap<T, U, V, W, X, Y>::set(IncomingKeyType&& key, IncomingMappedType&& mappe d) | 366 HashMap<T, U, V, W, X, Y>::set(IncomingKeyType&& key, IncomingMappedType&& mappe d) |
| 367 { | 367 { |
| 368 AddResult result = inlineAdd(std::forward<IncomingKeyType>(key), std::forwar d<IncomingMappedType>(mapped)); | 368 AddResult result = inlineAdd(std::forward<IncomingKeyType>(key), std::forwar d<IncomingMappedType>(mapped)); |
| 369 if (!result.isNewEntry) { | 369 if (!result.isNewEntry) { |
| 370 // The inlineAdd call above found an existing hash table entry; we need | 370 // The inlineAdd call above found an existing hash table entry; we need |
| 371 // to set the mapped value. | 371 // to set the mapped value. |
| 372 // | 372 // |
| 373 // It's safe to call std::forward again, because |mapped| isn't moved if there's an existing entry. | 373 // It's safe to call std::forward again, because |mapped| isn't moved if there's an existing entry. |
| 374 MappedTraits::store(std::forward<IncomingMappedType>(mapped), result.sto redValue->value); | 374 MappedTraits::store(std::move(std::forward<IncomingMappedType>(mapped)), result.storedValue->value); |
|
Yuta Kitamura
2016/09/05 06:46:09
Ditto.
Bugs Nash
2016/09/14 05:23:29
Done
| |
| 375 } | 375 } |
| 376 return result; | 376 return result; |
| 377 } | 377 } |
| 378 | 378 |
| 379 template <typename T, typename U, typename V, typename W, typename X, typename Y > | 379 template <typename T, typename U, typename V, typename W, typename X, typename Y > |
| 380 template <typename HashTranslator, typename IncomingKeyType, typename IncomingMa ppedType> | 380 template <typename HashTranslator, typename IncomingKeyType, typename IncomingMa ppedType> |
| 381 auto HashMap<T, U, V, W, X, Y>::add(IncomingKeyType&& key, IncomingMappedType&& mapped) -> AddResult | 381 auto HashMap<T, U, V, W, X, Y>::add(IncomingKeyType&& key, IncomingMappedType&& mapped) -> AddResult |
| 382 { | 382 { |
| 383 return m_impl.template addPassingHashCode<HashMapTranslatorAdapter<ValueTrai ts, HashTranslator>>( | 383 return m_impl.template addPassingHashCode<HashMapTranslatorAdapter<ValueTrai ts, HashTranslator>>( |
| 384 std::forward<IncomingKeyType>(key), std::forward<IncomingMappedType>(map ped)); | 384 std::forward<IncomingKeyType>(key), std::forward<IncomingMappedType>(map ped)); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 iterator end = collection.end().values(); | 497 iterator end = collection.end().values(); |
| 498 for (unsigned i = 0; it != end; ++it, ++i) | 498 for (unsigned i = 0; it != end; ++it, ++i) |
| 499 vector[i] = *it; | 499 vector[i] = *it; |
| 500 } | 500 } |
| 501 | 501 |
| 502 } // namespace WTF | 502 } // namespace WTF |
| 503 | 503 |
| 504 using WTF::HashMap; | 504 using WTF::HashMap; |
| 505 | 505 |
| 506 #endif // WTF_HashMap_h | 506 #endif // WTF_HashMap_h |
| OLD | NEW |