From 021a2b496a7eb7222c0c7f4d8cd01d697c3f2dda Mon Sep 17 00:00:00 2001 From: davidben Date: Wed, 20 Jan 2016 17:40:42 -0800 Subject: Revert of Allow std::unordered_*. (patchset #15 id:280001 of https://codereview.chromium.org/1502373009/ ) Reason for revert: MSan build failure. https://build.chromium.org/p/chromium.memory.fyi/builders/Chromium%20Linux%20ChromeOS%20MSan%20Builder/builds/12498 Original issue's description: > Allow std::unordered_*. > > base::hash_* is, as a transition step, implemented in terms of > std::unordered_*. Later commits will convert existing uses. > > Also fix a host of IWYU problems that arose from this CL. > > (NOPRESUBMIT because the wstring presubmit check is overzealous > and complains about the reference to wstring in the comment.) > > NOPRESUBMIT=true > BUG=576864 > TBR=derat@chromium.org,blundell@chromium.org,jbauman@chromium.org,dalecurtis@chromium.org > CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel > > Committed: https://crrev.com/3f37f7f1459e7b5a452c0e433493e0a6e9649ca7 > Cr-Commit-Position: refs/heads/master@{#370553} TBR=danakj@chromium.org,thakis@chromium.org,derat@chromium.org,blundell@chromium.org,dalecurtis@chromium.org,jbauman@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=576864 Review URL: https://codereview.chromium.org/1610023003 Cr-Commit-Position: refs/heads/master@{#370559} --- ash/display/display_info.cc | 5 +- base/containers/hash_tables.h | 252 +++++++++++++++++++-- base/containers/scoped_ptr_hash_map.h | 2 - base/hash.h | 81 ------- base/location.h | 4 +- base/strings/string16.h | 17 -- base/strings/string16_unittest.cc | 14 +- base/strings/string_piece.h | 6 +- cc/debug/picture_debug_util.cc | 1 - cc/layers/delegated_renderer_layer_impl.cc | 9 + cc/quads/render_pass.h | 3 +- cc/quads/render_pass_id.cc | 6 +- cc/quads/render_pass_id.h | 1 + cc/surfaces/surface_aggregator.cc | 9 + cc/surfaces/surface_sequence.h | 3 +- cc/tiles/image_decode_controller.h | 11 +- chrome/browser/devtools/devtools_file_watcher.cc | 1 - .../extensions/api/log_private/filter_handler.cc | 1 - chrome/browser/google/google_brand.cc | 1 - .../browser/spellchecker/spellcheck_host_metrics.h | 1 - .../drive_backend/metadata_database_index.h | 1 - .../web_contents/web_contents_tags_manager.cc | 2 - components/favicon_base/favicon_util.cc | 1 - components/mus/ws/display_manager.h | 1 - .../sync_bookmarks/bookmark_model_associator.h | 2 - .../gpu/browser_gpu_memory_buffer_manager.h | 3 +- .../service/framebuffer_completeness_cache.h | 2 - media/blink/multibuffer.h | 11 +- net/base/network_change_notifier_linux.h | 1 - net/base/port_util.cc | 1 - net/disk_cache/simple/simple_index_file.cc | 5 +- net/server/web_socket_encoder.cc | 1 - net/spdy/spdy_alt_svc_wire_format.cc | 1 - net/ssl/client_cert_store_nss.cc | 2 - net/tools/quic/quic_server_session_base_test.cc | 1 + net/tools/quic/quic_simple_server_session_test.cc | 1 + styleguide/c++/c++11.html | 44 ++-- ui/base/x/selection_utils.cc | 1 - .../ozone/layout/xkb/xkb_keyboard_layout_engine.cc | 2 - ui/gfx/generic_shared_memory_id.h | 4 +- 40 files changed, 305 insertions(+), 210 deletions(-) diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc index a85d175..b89d4d5 100644 --- a/ash/display/display_info.cc +++ b/ash/display/display_info.cc @@ -2,14 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ash/display/display_info.h" - #include - -#include #include #include +#include "ash/display/display_info.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" diff --git a/base/containers/hash_tables.h b/base/containers/hash_tables.h index 54bf98b..c421ddd 100644 --- a/base/containers/hash_tables.h +++ b/base/containers/hash_tables.h @@ -1,75 +1,281 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// + +// +// Deal with the differences between Microsoft and GNU implemenations +// of hash_map. Allows all platforms to use |base::hash_map| and +// |base::hash_set|. +// eg: +// base::hash_map my_map; +// base::hash_set my_set; +// +// NOTE: It is an explicit non-goal of this class to provide a generic hash +// function for pointers. If you want to hash a pointers to a particular class, +// please define the template specialization elsewhere (for example, in its +// header file) and keep it specific to just pointers to that class. This is +// because identity hashes are not desirable for all types that might show up +// in containers as pointers. #ifndef BASE_CONTAINERS_HASH_TABLES_H_ #define BASE_CONTAINERS_HASH_TABLES_H_ -#include +#include +#include + +#include + +#include "base/strings/string16.h" +#include "build/build_config.h" + +#if defined(COMPILER_MSVC) #include #include -#include -#include "base/hash.h" +#define BASE_HASH_NAMESPACE std -// This header file is deprecated. Use the corresponding C++11 type -// instead. https://crbug.com/576864 +#elif defined(COMPILER_GCC) -// Use a custom hasher instead. #define BASE_HASH_NAMESPACE base_hash +// This is a hack to disable the gcc 4.4 warning about hash_map and hash_set +// being deprecated. We can get rid of this when we upgrade to VS2008 and we +// can use and . +#ifdef __DEPRECATED +#define CHROME_OLD__DEPRECATED __DEPRECATED +#undef __DEPRECATED +#endif + +#include +#include +#define BASE_HASH_IMPL_NAMESPACE __gnu_cxx + +#include + +#ifdef CHROME_OLD__DEPRECATED +#define __DEPRECATED CHROME_OLD__DEPRECATED +#undef CHROME_OLD__DEPRECATED +#endif + namespace BASE_HASH_NAMESPACE { -// A separate hasher which, by default, forwards to std::hash. This is so legacy -// uses of BASE_HASH_NAMESPACE with base::hash_map do not interfere with -// std::hash mid-transition. +// The pre-standard hash behaves like C++11's std::hash, except around pointers. +// const char* is specialized to hash the C string and hash functions for +// general T* are missing. Define a BASE_HASH_NAMESPACE::hash which aligns with +// the C++11 behavior. + template struct hash { std::size_t operator()(const T& value) const { - return std::hash()(value); + return BASE_HASH_IMPL_NAMESPACE::hash()(value); } }; -// Use base::IntPairHash from base/hash.h as a custom hasher instead. -template -struct hash > { - std::size_t operator()(std::pair value) const { - return base::HashInts(value.first, value.second); +template +struct hash { + std::size_t operator()(T* value) const { + return BASE_HASH_IMPL_NAMESPACE::hash()( + reinterpret_cast(value)); } }; +// The GNU C++ library provides identity hash functions for many integral types, +// but not for |long long|. This hash function will truncate if |size_t| is +// narrower than |long long|. This is probably good enough for what we will +// use it for. + +#define DEFINE_TRIVIAL_HASH(integral_type) \ + template<> \ + struct hash { \ + std::size_t operator()(integral_type value) const { \ + return static_cast(value); \ + } \ + } + +DEFINE_TRIVIAL_HASH(long long); +DEFINE_TRIVIAL_HASH(unsigned long long); + +#undef DEFINE_TRIVIAL_HASH + +// Implement string hash functions so that strings of various flavors can +// be used as keys in STL maps and sets. The hash algorithm comes from the +// GNU C++ library, in . It is duplicated here because GCC +// versions prior to 4.3.2 are unable to compile when RTTI +// is disabled, as it is in our build. + +#define DEFINE_STRING_HASH(string_type) \ + template<> \ + struct hash { \ + std::size_t operator()(const string_type& s) const { \ + std::size_t result = 0; \ + for (string_type::const_iterator i = s.begin(); i != s.end(); ++i) \ + result = (result * 131) + *i; \ + return result; \ + } \ + } + +DEFINE_STRING_HASH(std::string); +DEFINE_STRING_HASH(base::string16); + +#undef DEFINE_STRING_HASH + } // namespace BASE_HASH_NAMESPACE +#else // COMPILER +#error define BASE_HASH_NAMESPACE for your compiler +#endif // COMPILER + namespace base { -// Use std::unordered_map instead. +// On MSVC, use the C++11 containers. +#if defined(COMPILER_MSVC) + template, + class Hash = std::hash, class Pred = std::equal_to, class Alloc = std::allocator>> using hash_map = std::unordered_map; -// Use std::unordered_multimap instead. template, + class Hash = std::hash, class Pred = std::equal_to, class Alloc = std::allocator>> using hash_multimap = std::unordered_multimap; -// Use std::unordered_multiset instead. template, + class Hash = std::hash, class Pred = std::equal_to, class Alloc = std::allocator> using hash_multiset = std::unordered_multiset; -// Use std::unordered_set instead. template, + class Hash = std::hash, class Pred = std::equal_to, class Alloc = std::allocator> using hash_set = std::unordered_set; +#else // !COMPILER_MSVC + +// Otherwise, use the pre-standard ones, but override the default hash to match +// C++11. +template, + class Pred = std::equal_to, + class Alloc = std::allocator>> +using hash_map = BASE_HASH_IMPL_NAMESPACE::hash_map; + +template, + class Pred = std::equal_to, + class Alloc = std::allocator>> +using hash_multimap = + BASE_HASH_IMPL_NAMESPACE::hash_multimap; + +template, + class Pred = std::equal_to, + class Alloc = std::allocator> +using hash_multiset = + BASE_HASH_IMPL_NAMESPACE::hash_multiset; + +template, + class Pred = std::equal_to, + class Alloc = std::allocator> +using hash_set = BASE_HASH_IMPL_NAMESPACE::hash_set; + +#undef BASE_HASH_IMPL_NAMESPACE + +#endif // COMPILER_MSVC + +// Implement hashing for pairs of at-most 32 bit integer values. +// When size_t is 32 bits, we turn the 64-bit hash code into 32 bits by using +// multiply-add hashing. This algorithm, as described in +// Theorem 4.3.3 of the thesis "Über die Komplexität der Multiplikation in +// eingeschränkten Branchingprogrammmodellen" by Woelfel, is: +// +// h32(x32, y32) = (h64(x32, y32) * rand_odd64 + rand16 * 2^16) % 2^64 / 2^32 +// +// Contact danakj@chromium.org for any questions. +inline std::size_t HashInts32(uint32_t value1, uint32_t value2) { + uint64_t value1_64 = value1; + uint64_t hash64 = (value1_64 << 32) | value2; + + if (sizeof(std::size_t) >= sizeof(uint64_t)) + return static_cast(hash64); + + uint64_t odd_random = 481046412LL << 32 | 1025306955LL; + uint32_t shift_random = 10121U << 16; + + hash64 = hash64 * odd_random + shift_random; + std::size_t high_bits = static_cast( + hash64 >> (8 * (sizeof(uint64_t) - sizeof(std::size_t)))); + return high_bits; +} + +// Implement hashing for pairs of up-to 64-bit integer values. +// We use the compound integer hash method to produce a 64-bit hash code, by +// breaking the two 64-bit inputs into 4 32-bit values: +// http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000 +// Then we reduce our result to 32 bits if required, similar to above. +inline std::size_t HashInts64(uint64_t value1, uint64_t value2) { + uint32_t short_random1 = 842304669U; + uint32_t short_random2 = 619063811U; + uint32_t short_random3 = 937041849U; + uint32_t short_random4 = 3309708029U; + + uint32_t value1a = static_cast(value1 & 0xffffffff); + uint32_t value1b = static_cast((value1 >> 32) & 0xffffffff); + uint32_t value2a = static_cast(value2 & 0xffffffff); + uint32_t value2b = static_cast((value2 >> 32) & 0xffffffff); + + uint64_t product1 = static_cast(value1a) * short_random1; + uint64_t product2 = static_cast(value1b) * short_random2; + uint64_t product3 = static_cast(value2a) * short_random3; + uint64_t product4 = static_cast(value2b) * short_random4; + + uint64_t hash64 = product1 + product2 + product3 + product4; + + if (sizeof(std::size_t) >= sizeof(uint64_t)) + return static_cast(hash64); + + uint64_t odd_random = 1578233944LL << 32 | 194370989LL; + uint32_t shift_random = 20591U << 16; + + hash64 = hash64 * odd_random + shift_random; + std::size_t high_bits = static_cast( + hash64 >> (8 * (sizeof(uint64_t) - sizeof(std::size_t)))); + return high_bits; +} + +template +inline std::size_t HashPair(T1 value1, T2 value2) { + // This condition is expected to be compile-time evaluated and optimised away + // in release builds. + if (sizeof(T1) > sizeof(uint32_t) || (sizeof(T2) > sizeof(uint32_t))) + return HashInts64(value1, value2); + + return HashInts32(value1, value2); +} + } // namespace base +namespace BASE_HASH_NAMESPACE { + +// Implement methods for hashing a pair of integers, so they can be used as +// keys in STL containers. + +template +struct hash > { + std::size_t operator()(std::pair value) const { + return base::HashPair(value.first, value.second); + } +}; + +} // namespace BASE_HASH_NAMESPACE + +#undef DEFINE_PAIR_HASH_FUNCTION_START +#undef DEFINE_PAIR_HASH_FUNCTION_END + #endif // BASE_CONTAINERS_HASH_TABLES_H_ diff --git a/base/containers/scoped_ptr_hash_map.h b/base/containers/scoped_ptr_hash_map.h index dd100c6..189c314 100644 --- a/base/containers/scoped_ptr_hash_map.h +++ b/base/containers/scoped_ptr_hash_map.h @@ -18,8 +18,6 @@ namespace base { -// Deprecated. Use std::unordered_map instead. https://crbug.com/579229 -// // This type acts like a hash_map >, based on top of // base::hash_map. The ScopedPtrHashMap has ownership of all values in the data // structure. diff --git a/base/hash.h b/base/hash.h index d5dc549..ed8d9fd 100644 --- a/base/hash.h +++ b/base/hash.h @@ -10,7 +10,6 @@ #include #include -#include #include "base/base_export.h" #include "base/logging.h" @@ -36,86 +35,6 @@ inline uint32_t Hash(const std::string& str) { return Hash(str.data(), str.size()); } -// Implement hashing for pairs of at-most 32 bit integer values. -// When size_t is 32 bits, we turn the 64-bit hash code into 32 bits by using -// multiply-add hashing. This algorithm, as described in -// Theorem 4.3.3 of the thesis "Über die Komplexität der Multiplikation in -// eingeschränkten Branchingprogrammmodellen" by Woelfel, is: -// -// h32(x32, y32) = (h64(x32, y32) * rand_odd64 + rand16 * 2^16) % 2^64 / 2^32 -// -// Contact danakj@chromium.org for any questions. -inline size_t HashInts32(uint32_t value1, uint32_t value2) { - uint64_t value1_64 = value1; - uint64_t hash64 = (value1_64 << 32) | value2; - - if (sizeof(size_t) >= sizeof(uint64_t)) - return static_cast(hash64); - - uint64_t odd_random = 481046412LL << 32 | 1025306955LL; - uint32_t shift_random = 10121U << 16; - - hash64 = hash64 * odd_random + shift_random; - size_t high_bits = static_cast( - hash64 >> (8 * (sizeof(uint64_t) - sizeof(size_t)))); - return high_bits; -} - -// Implement hashing for pairs of up-to 64-bit integer values. -// We use the compound integer hash method to produce a 64-bit hash code, by -// breaking the two 64-bit inputs into 4 32-bit values: -// http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000 -// Then we reduce our result to 32 bits if required, similar to above. -inline size_t HashInts64(uint64_t value1, uint64_t value2) { - uint32_t short_random1 = 842304669U; - uint32_t short_random2 = 619063811U; - uint32_t short_random3 = 937041849U; - uint32_t short_random4 = 3309708029U; - - uint32_t value1a = static_cast(value1 & 0xffffffff); - uint32_t value1b = static_cast((value1 >> 32) & 0xffffffff); - uint32_t value2a = static_cast(value2 & 0xffffffff); - uint32_t value2b = static_cast((value2 >> 32) & 0xffffffff); - - uint64_t product1 = static_cast(value1a) * short_random1; - uint64_t product2 = static_cast(value1b) * short_random2; - uint64_t product3 = static_cast(value2a) * short_random3; - uint64_t product4 = static_cast(value2b) * short_random4; - - uint64_t hash64 = product1 + product2 + product3 + product4; - - if (sizeof(size_t) >= sizeof(uint64_t)) - return static_cast(hash64); - - uint64_t odd_random = 1578233944LL << 32 | 194370989LL; - uint32_t shift_random = 20591U << 16; - - hash64 = hash64 * odd_random + shift_random; - size_t high_bits = static_cast( - hash64 >> (8 * (sizeof(uint64_t) - sizeof(size_t)))); - return high_bits; -} - -template -inline size_t HashInts(T1 value1, T2 value2) { - // This condition is expected to be compile-time evaluated and optimised away - // in release builds. - if (sizeof(T1) > sizeof(uint32_t) || (sizeof(T2) > sizeof(uint32_t))) - return HashInts64(value1, value2); - - return HashInts32(value1, value2); -} - -// A templated hasher for pairs of integer types. -template struct IntPairHash; - -template -struct IntPairHash> { - size_t operator()(std::pair value) const { - return HashInts(value.first, value.second); - } -}; - } // namespace base #endif // BASE_HASH_H_ diff --git a/base/location.h b/base/location.h index 21e270c..d3bb23c 100644 --- a/base/location.h +++ b/base/location.h @@ -11,7 +11,7 @@ #include #include "base/base_export.h" -#include "base/hash.h" +#include "base/containers/hash_tables.h" namespace tracked_objects { @@ -59,7 +59,7 @@ class BASE_EXPORT Location { // it comes from __FILE__, so no need to check the contents of the string. // See the definition of FROM_HERE in location.h, and how it is used // elsewhere. - return base::HashInts(reinterpret_cast(location.file_name()), + return base::HashPair(reinterpret_cast(location.file_name()), location.line_number()); } }; diff --git a/base/strings/string16.h b/base/strings/string16.h index af44a5c..e47669c 100644 --- a/base/strings/string16.h +++ b/base/strings/string16.h @@ -29,8 +29,6 @@ #include #include #include - -#include #include #include "base/base_export.h" @@ -184,21 +182,6 @@ BASE_EXPORT extern void PrintTo(const string16& str, std::ostream* out); extern template class BASE_EXPORT std::basic_string; -// Specialize std::hash for base::string16. Although the style guide forbids -// this in general, it is necessary for consistency with WCHAR_T_IS_UTF16 -// platforms, where base::string16 is a type alias for std::wstring. -namespace std { -template<> -struct hash { - std::size_t operator()(const base::string16& s) const { - std::size_t result = 0; - for (base::char16 c : s) - result = (result * 131) + c; - return result; - } -}; -} // namespace std - #endif // WCHAR_T_IS_UTF32 #endif // BASE_STRINGS_STRING16_H_ diff --git a/base/strings/string16_unittest.cc b/base/strings/string16_unittest.cc index 0d2ca80..4e58218 100644 --- a/base/strings/string16_unittest.cc +++ b/base/strings/string16_unittest.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include -#include #include "base/strings/string16.h" @@ -12,6 +11,8 @@ namespace base { +#if defined(WCHAR_T_IS_UTF32) + // We define a custom operator<< for string16 so we can use it with logging. // This tests that conversion. TEST(String16Test, OutputStream) { @@ -52,15 +53,6 @@ TEST(String16Test, OutputStream) { } } -TEST(String16Test, Hash) { - string16 str1 = ASCIIToUTF16("hello"); - string16 str2 = ASCIIToUTF16("world"); - - std::unordered_set set; - - set.insert(str1); - EXPECT_EQ(1u, set.count(str1)); - EXPECT_EQ(0u, set.count(str2)); -} +#endif } // namespace base diff --git a/base/strings/string_piece.h b/base/strings/string_piece.h index 92634b9..31e7596 100644 --- a/base/strings/string_piece.h +++ b/base/strings/string_piece.h @@ -439,9 +439,9 @@ BASE_EXPORT std::ostream& operator<<(std::ostream& o, // We provide appropriate hash functions so StringPiece and StringPiece16 can // be used as keys in hash sets and maps. -// This hash function is copied from base/strings/string16.h. We don't use the -// ones already defined for string and string16 directly because it would -// require the string constructors to be called, which we don't want. +// This hash function is copied from base/containers/hash_tables.h. We don't +// use the ones already defined for string and string16 directly because it +// would require the string constructors to be called, which we don't want. #define HASH_STRING_PIECE(StringPieceType, string_piece) \ std::size_t result = 0; \ for (StringPieceType::const_iterator i = string_piece.begin(); \ diff --git a/cc/debug/picture_debug_util.cc b/cc/debug/picture_debug_util.cc index 50ae60b..b1879af 100644 --- a/cc/debug/picture_debug_util.cc +++ b/cc/debug/picture_debug_util.cc @@ -6,7 +6,6 @@ #include -#include #include #include "base/base64.h" diff --git a/cc/layers/delegated_renderer_layer_impl.cc b/cc/layers/delegated_renderer_layer_impl.cc index 8158edcf..5d51116 100644 --- a/cc/layers/delegated_renderer_layer_impl.cc +++ b/cc/layers/delegated_renderer_layer_impl.cc @@ -109,7 +109,16 @@ void DelegatedRendererLayerImpl::SetFrameData( bool invalid_frame = false; ResourceProvider::ResourceIdSet resources_in_frame; size_t reserve_size = frame_data->resource_list.size(); +#if defined(COMPILER_MSVC) resources_in_frame.reserve(reserve_size); +#elif defined(COMPILER_GCC) + // Pre-standard hash-tables only implement resize, which behaves similarly + // to reserve for these keys. Resizing to 0 may also be broken (particularly + // on stlport). + // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. + if (reserve_size) + resources_in_frame.resize(reserve_size); +#endif for (const auto& pass : render_pass_list) { for (const auto& quad : pass->quad_list) { for (ResourceId& resource_id : quad->resources) { diff --git a/cc/quads/render_pass.h b/cc/quads/render_pass.h index 552643d..9ba727e 100644 --- a/cc/quads/render_pass.h +++ b/cc/quads/render_pass.h @@ -12,7 +12,6 @@ #include "base/callback.h" #include "base/containers/hash_tables.h" -#include "base/hash.h" #include "base/macros.h" #include "cc/base/cc_export.h" #include "cc/base/list_container.h" @@ -140,7 +139,7 @@ namespace BASE_HASH_NAMESPACE { template <> struct hash { size_t operator()(cc::RenderPassId key) const { - return base::HashInts(key.layer_id, static_cast(key.index)); + return base::HashPair(key.layer_id, static_cast(key.index)); } }; } // namespace BASE_HASH_NAMESPACE diff --git a/cc/quads/render_pass_id.cc b/cc/quads/render_pass_id.cc index 742c191..0f53e81 100644 --- a/cc/quads/render_pass_id.cc +++ b/cc/quads/render_pass_id.cc @@ -2,11 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cc/quads/render_pass_id.h" - #include -#include "base/hash.h" +#include "cc/quads/render_pass_id.h" namespace cc { @@ -14,7 +12,7 @@ void* RenderPassId::AsTracingId() const { static_assert(sizeof(size_t) <= sizeof(void*), // NOLINT "size of size_t should not be greater than that of a pointer"); return reinterpret_cast( - base::HashInts(layer_id, static_cast(index))); + base::HashPair(layer_id, static_cast(index))); } } // namespace cc diff --git a/cc/quads/render_pass_id.h b/cc/quads/render_pass_id.h index 5dff1e1..11cb777 100644 --- a/cc/quads/render_pass_id.h +++ b/cc/quads/render_pass_id.h @@ -9,6 +9,7 @@ #include +#include "base/containers/hash_tables.h" #include "cc/base/cc_export.h" namespace cc { diff --git a/cc/surfaces/surface_aggregator.cc b/cc/surfaces/surface_aggregator.cc index d60a217..9901d00 100644 --- a/cc/surfaces/surface_aggregator.cc +++ b/cc/surfaces/surface_aggregator.cc @@ -526,7 +526,16 @@ gfx::Rect SurfaceAggregator::PrewalkTree(SurfaceId surface_id, ResourceProvider::ResourceIdSet referenced_resources; size_t reserve_size = frame_data->resource_list.size(); +#if defined(COMPILER_MSVC) referenced_resources.reserve(reserve_size); +#elif defined(COMPILER_GCC) + // Pre-standard hash-tables only implement resize, which behaves similarly + // to reserve for these keys. Resizing to 0 may also be broken (particularly + // on stlport). + // TODO(jbauman): Replace with reserve when C++11 is supported everywhere. + if (reserve_size) + referenced_resources.resize(reserve_size); +#endif bool invalid_frame = false; ResourceProvider::ResourceIdMap empty_map; diff --git a/cc/surfaces/surface_sequence.h b/cc/surfaces/surface_sequence.h index b4ab8ef..21decf6 100644 --- a/cc/surfaces/surface_sequence.h +++ b/cc/surfaces/surface_sequence.h @@ -11,7 +11,6 @@ #include #include "base/containers/hash_tables.h" -#include "base/hash.h" namespace cc { @@ -47,7 +46,7 @@ namespace BASE_HASH_NAMESPACE { template <> struct hash { size_t operator()(cc::SurfaceSequence key) const { - return base::HashInts(key.id_namespace, key.sequence); + return base::HashPair(key.id_namespace, key.sequence); } }; } // namespace BASE_HASH_NAMESPACE diff --git a/cc/tiles/image_decode_controller.h b/cc/tiles/image_decode_controller.h index f814d21..2c18212 100644 --- a/cc/tiles/image_decode_controller.h +++ b/cc/tiles/image_decode_controller.h @@ -8,7 +8,6 @@ #include #include "base/containers/hash_tables.h" -#include "base/hash.h" #include "base/memory/discardable_memory_allocator.h" #include "base/memory/ref_counted.h" #include "base/numerics/safe_math.h" @@ -80,16 +79,16 @@ struct hash { // TODO(vmpstr): This is a mess. Maybe it's faster to just search the vector // always (forwards or backwards to account for LRU). uint64_t src_rect_hash = - base::HashInts(static_cast(base::HashInts( + base::HashPair(static_cast(base::HashPair( key.src_rect().x(), key.src_rect().y())), - static_cast(base::HashInts( + static_cast(base::HashPair( key.src_rect().width(), key.src_rect().height()))); uint64_t target_size_hash = - base::HashInts(key.target_size().width(), key.target_size().height()); + base::HashPair(key.target_size().width(), key.target_size().height()); - return base::HashInts(base::HashInts(src_rect_hash, target_size_hash), - base::HashInts(key.image_id(), key.filter_quality())); + return base::HashPair(base::HashPair(src_rect_hash, target_size_hash), + base::HashPair(key.image_id(), key.filter_quality())); } }; } // namespace BASE_HASH_NAMESPACE diff --git a/chrome/browser/devtools/devtools_file_watcher.cc b/chrome/browser/devtools/devtools_file_watcher.cc index d966de5..bfc4906 100644 --- a/chrome/browser/devtools/devtools_file_watcher.cc +++ b/chrome/browser/devtools/devtools_file_watcher.cc @@ -4,7 +4,6 @@ #include "chrome/browser/devtools/devtools_file_watcher.h" -#include #include #include diff --git a/chrome/browser/extensions/api/log_private/filter_handler.cc b/chrome/browser/extensions/api/log_private/filter_handler.cc index 02c1306..6965932 100644 --- a/chrome/browser/extensions/api/log_private/filter_handler.cc +++ b/chrome/browser/extensions/api/log_private/filter_handler.cc @@ -4,7 +4,6 @@ #include "chrome/browser/extensions/api/log_private/filter_handler.h" -#include #include #include diff --git a/chrome/browser/google/google_brand.cc b/chrome/browser/google/google_brand.cc index 7e07284e..5360948 100644 --- a/chrome/browser/google/google_brand.cc +++ b/chrome/browser/google/google_brand.cc @@ -4,7 +4,6 @@ #include "chrome/browser/google/google_brand.h" -#include #include #include "base/macros.h" diff --git a/chrome/browser/spellchecker/spellcheck_host_metrics.h b/chrome/browser/spellchecker/spellcheck_host_metrics.h index 05da7ce..fe0df15 100644 --- a/chrome/browser/spellchecker/spellcheck_host_metrics.h +++ b/chrome/browser/spellchecker/spellcheck_host_metrics.h @@ -11,7 +11,6 @@ #include #include "base/containers/hash_tables.h" -#include "base/strings/string16.h" #include "base/time/time.h" #include "base/timer/timer.h" diff --git a/chrome/browser/sync_file_system/drive_backend/metadata_database_index.h b/chrome/browser/sync_file_system/drive_backend/metadata_database_index.h index 4069652..a6f4510 100644 --- a/chrome/browser/sync_file_system/drive_backend/metadata_database_index.h +++ b/chrome/browser/sync_file_system/drive_backend/metadata_database_index.h @@ -15,7 +15,6 @@ #include "base/containers/hash_tables.h" #include "base/containers/scoped_ptr_hash_map.h" -#include "base/hash.h" #include "base/macros.h" #include "base/memory/scoped_vector.h" #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index_interface.h" diff --git a/chrome/browser/task_management/providers/web_contents/web_contents_tags_manager.cc b/chrome/browser/task_management/providers/web_contents/web_contents_tags_manager.cc index 96800d9..3bd7a34 100644 --- a/chrome/browser/task_management/providers/web_contents/web_contents_tags_manager.cc +++ b/chrome/browser/task_management/providers/web_contents/web_contents_tags_manager.cc @@ -4,8 +4,6 @@ #include "chrome/browser/task_management/providers/web_contents/web_contents_tags_manager.h" -#include - #include "base/memory/singleton.h" #include "chrome/browser/task_management/providers/web_contents/web_contents_task_provider.h" diff --git a/components/favicon_base/favicon_util.cc b/components/favicon_base/favicon_util.cc index e17ebdf..8c66920 100644 --- a/components/favicon_base/favicon_util.cc +++ b/components/favicon_base/favicon_util.cc @@ -6,7 +6,6 @@ #include -#include #include #include "build/build_config.h" diff --git a/components/mus/ws/display_manager.h b/components/mus/ws/display_manager.h index 4cf6e4b..32f0c63 100644 --- a/components/mus/ws/display_manager.h +++ b/components/mus/ws/display_manager.h @@ -12,7 +12,6 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/strings/string16.h" #include "base/timer/timer.h" #include "build/build_config.h" #include "components/mus/public/interfaces/window_tree.mojom.h" diff --git a/components/sync_bookmarks/bookmark_model_associator.h b/components/sync_bookmarks/bookmark_model_associator.h index f10e8d4..d5c777c 100644 --- a/components/sync_bookmarks/bookmark_model_associator.h +++ b/components/sync_bookmarks/bookmark_model_associator.h @@ -15,11 +15,9 @@ #include #include "base/compiler_specific.h" -#include "base/containers/hash_tables.h" #include "base/hash.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "base/strings/string16.h" #include "base/threading/thread_checker.h" #include "components/sync_driver/data_type_error_handler.h" #include "components/sync_driver/model_associator.h" diff --git a/content/browser/gpu/browser_gpu_memory_buffer_manager.h b/content/browser/gpu/browser_gpu_memory_buffer_manager.h index 94095f1..0057192 100644 --- a/content/browser/gpu/browser_gpu_memory_buffer_manager.h +++ b/content/browser/gpu/browser_gpu_memory_buffer_manager.h @@ -12,7 +12,6 @@ #include "base/callback.h" #include "base/containers/hash_tables.h" -#include "base/hash.h" #include "base/macros.h" #include "base/trace_event/memory_dump_provider.h" #include "content/common/content_export.h" @@ -32,7 +31,7 @@ namespace BASE_HASH_NAMESPACE { template <> struct hash { size_t operator()(const content::GpuMemoryBufferConfigurationKey& key) const { - return base::HashInts(static_cast(key.first), + return base::HashPair(static_cast(key.first), static_cast(key.second)); } }; diff --git a/gpu/command_buffer/service/framebuffer_completeness_cache.h b/gpu/command_buffer/service/framebuffer_completeness_cache.h index 932aa62..44741a4 100644 --- a/gpu/command_buffer/service/framebuffer_completeness_cache.h +++ b/gpu/command_buffer/service/framebuffer_completeness_cache.h @@ -5,8 +5,6 @@ #ifndef GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_COMPLETENESS_CACHE_H_ #define GPU_COMMAND_BUFFER_SERVICE_FRAMEBUFFER_COMPLETENESS_CACHE_H_ -#include - #include "base/containers/hash_tables.h" #include "base/macros.h" #include "base/memory/ref_counted.h" diff --git a/media/blink/multibuffer.h b/media/blink/multibuffer.h index cecca4a..6478914 100644 --- a/media/blink/multibuffer.h +++ b/media/blink/multibuffer.h @@ -15,7 +15,6 @@ #include "base/callback.h" #include "base/containers/hash_tables.h" -#include "base/hash.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -44,7 +43,15 @@ namespace BASE_HASH_NAMESPACE { template <> struct hash { std::size_t operator()(const media::MultiBufferGlobalBlockId& key) const { - return base::HashInts(reinterpret_cast(key.first), key.second); +// It would be nice if we could use intptr_t instead of int64_t here, but +// on some platforms, int64_t is declared as "long" which doesn't match +// any of the HashPair() functions. This leads to a compile error since +// the compiler can't decide which HashPair() function to call. +#if defined(ARCH_CPU_64_BITS) + return base::HashPair(reinterpret_cast(key.first), key.second); +#else + return base::HashPair(reinterpret_cast(key.first), key.second); +#endif } }; diff --git a/net/base/network_change_notifier_linux.h b/net/base/network_change_notifier_linux.h index 48bda6b..85238cf9 100644 --- a/net/base/network_change_notifier_linux.h +++ b/net/base/network_change_notifier_linux.h @@ -6,7 +6,6 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_LINUX_H_ #include "base/compiler_specific.h" -#include "base/containers/hash_tables.h" #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "net/base/net_export.h" diff --git a/net/base/port_util.cc b/net/base/port_util.cc index 7328b5e..1867dc3 100644 --- a/net/base/port_util.cc +++ b/net/base/port_util.cc @@ -4,7 +4,6 @@ #include "net/base/port_util.h" -#include #include #include "base/lazy_instance.h" diff --git a/net/disk_cache/simple/simple_index_file.cc b/net/disk_cache/simple/simple_index_file.cc index 025ffe9..7e80c02 100644 --- a/net/disk_cache/simple/simple_index_file.cc +++ b/net/disk_cache/simple/simple_index_file.cc @@ -423,7 +423,10 @@ void SimpleIndexFile::Deserialize(const char* data, int data_len, return; } - entries->reserve(index_metadata.GetNumberOfEntries() + kExtraSizeForMerge); +#if !defined(OS_WIN) + // TODO(gavinp): Consider using std::unordered_map. + entries->resize(index_metadata.GetNumberOfEntries() + kExtraSizeForMerge); +#endif while (entries->size() < index_metadata.GetNumberOfEntries()) { uint64_t hash_key; EntryMetadata entry_metadata; diff --git a/net/server/web_socket_encoder.cc b/net/server/web_socket_encoder.cc index d90a156..6d59713 100644 --- a/net/server/web_socket_encoder.cc +++ b/net/server/web_socket_encoder.cc @@ -4,7 +4,6 @@ #include "net/server/web_socket_encoder.h" -#include #include #include diff --git a/net/spdy/spdy_alt_svc_wire_format.cc b/net/spdy/spdy_alt_svc_wire_format.cc index a50590e..ba32160 100644 --- a/net/spdy/spdy_alt_svc_wire_format.cc +++ b/net/spdy/spdy_alt_svc_wire_format.cc @@ -4,7 +4,6 @@ #include "net/spdy/spdy_alt_svc_wire_format.h" -#include #include #include diff --git a/net/ssl/client_cert_store_nss.cc b/net/ssl/client_cert_store_nss.cc index ef29b55..8a6c329 100644 --- a/net/ssl/client_cert_store_nss.cc +++ b/net/ssl/client_cert_store_nss.cc @@ -6,8 +6,6 @@ #include #include - -#include #include #include "base/bind.h" diff --git a/net/tools/quic/quic_server_session_base_test.cc b/net/tools/quic/quic_server_session_base_test.cc index efe96ec..36432aa 100644 --- a/net/tools/quic/quic_server_session_base_test.cc +++ b/net/tools/quic/quic_server_session_base_test.cc @@ -26,6 +26,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +using __gnu_cxx::vector; using net::test::CryptoTestUtils; using net::test::MockConnection; using net::test::MockConnectionHelper; diff --git a/net/tools/quic/quic_simple_server_session_test.cc b/net/tools/quic/quic_simple_server_session_test.cc index fe9482f..e3ed3c9 100644 --- a/net/tools/quic/quic_simple_server_session_test.cc +++ b/net/tools/quic/quic_simple_server_session_test.cc @@ -30,6 +30,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +using __gnu_cxx::vector; using net::test::CryptoTestUtils; using net::test::MockConnection; using net::test::MockConnectionHelper; diff --git a/styleguide/c++/c++11.html b/styleguide/c++/c++11.html index 8c3cbc0..2776be9 100644 --- a/styleguide/c++/c++11.html +++ b/styleguide/c++/c++11.html @@ -363,17 +363,6 @@ std::end -Forwarding references -std::forward() -Perfectly forwards arguments (including rvalues) -std::forward - - Allowed, though usage should be rare (primarily for forwarding constructor arguments, or in carefully reviewed library code). - Discussion thread - - - - Lexicographical struct comparison tie(a, b, c) <
  tie(rhs.a, rhs.b, rhs.c)
Idiom for operator< implementation @@ -406,6 +395,17 @@ std::end +Forwarding references +std::forward() +Perfectly forwards arguments (including rvalues) +std::forward + + Allowed, though usage should be rare (primarily for forwarding constructor arguments, or in carefully reviewed library code). + Discussion thread + + + + Type Traits Class templates within <type_traits> Allows compile-time inspection of the properties of types @@ -422,17 +422,6 @@ Standard library header <type_traits> Anything in <cmath> is allowed. Discussion thread - -Unordered Associative Containers -std::unordered_set, std::unordered_map, -std::unordered_multiset, and std::unordered_multimap -Allows efficient containers of key/value pairs -std::unordered_map -and std::unordered_set - -Per the Google style guide, specify custom hashers instead of specializing std::hash for custom types. Discussion thread. - - @@ -1069,6 +1058,17 @@ Ownership and Smart Pointers +Unordered Associative Containers +std::unordered_set, std::unordered_map, +std::unordered_multiset, and std::unordered_multimap +Allows efficient containers of key/value pairs +std::unordered_map +and std::unordered_set + + + + + Variadic Copy Macro va_copy(va_list dest, va_list src) Makes a copy of the variadic function arguments diff --git a/ui/base/x/selection_utils.cc b/ui/base/x/selection_utils.cc index 7b76e5f..af84c4b 100644 --- a/ui/base/x/selection_utils.cc +++ b/ui/base/x/selection_utils.cc @@ -6,7 +6,6 @@ #include -#include #include #include "base/i18n/icu_string_conversions.h" diff --git a/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc b/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc index f85b651..aee2282 100644 --- a/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc +++ b/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.cc @@ -7,8 +7,6 @@ #include #include -#include - #include "base/bind.h" #include "base/location.h" #include "base/logging.h" diff --git a/ui/gfx/generic_shared_memory_id.h b/ui/gfx/generic_shared_memory_id.h index b18c869..51f553b 100644 --- a/ui/gfx/generic_shared_memory_id.h +++ b/ui/gfx/generic_shared_memory_id.h @@ -8,8 +8,6 @@ #include #include -#include "base/containers/hash_tables.h" -#include "base/hash.h" #include "base/trace_event/memory_allocator_dump.h" #include "ui/gfx/gfx_export.h" @@ -60,7 +58,7 @@ template struct hash> { size_t operator()( const std::pair& pair) const { - return base::HashInts(pair.first.id, pair.second); + return base::HashPair(pair.first.id, pair.second); } }; -- cgit v1.1