summaryrefslogtreecommitdiffstats
path: root/libcxx/include/variant
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-12-04 21:37:37 +0000
committerEric Fiselier <eric@efcs.ca>2016-12-04 21:37:37 +0000
commit02460bac8bc2c8c84ef1813fb30f22a64352a6ef (patch)
tree113f9d408982b945f902ab94221ed0423c06388f /libcxx/include/variant
parent7f4e0766f17da3aa5d6e651452ba756d42f188ff (diff)
downloadbcm5719-llvm-02460bac8bc2c8c84ef1813fb30f22a64352a6ef.tar.gz
bcm5719-llvm-02460bac8bc2c8c84ef1813fb30f22a64352a6ef.zip
Choose better hash values for std::monostate and valueless variants.
Previously these hashes were 0 and -1 respectively. These seem like common sentinel values and should be avoided to prevent needless collisions. This patch changes those values to different arbitrary numbers, which should hopefully cause less collisions. Because I couldn't help myself I choose the fundamental constants for gravity and the speed of light. llvm-svn: 288623
Diffstat (limited to 'libcxx/include/variant')
-rw-r--r--libcxx/include/variant6
1 files changed, 4 insertions, 2 deletions
diff --git a/libcxx/include/variant b/libcxx/include/variant
index a7352577773..22d6b6c9472 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -1538,7 +1538,7 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<variant<_Types...>> {
using __variant_detail::__visitation::__variant;
size_t __res =
__v.valueless_by_exception()
- ? __v.index()
+ ? 299792458 // Random value chosen by the universe upon creation
: __variant::__visit_alt(
[](const auto& __alt) {
using __alt_type = decay_t<decltype(__alt)>;
@@ -1556,7 +1556,9 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<monostate> {
using result_type = size_t;
inline _LIBCPP_INLINE_VISIBILITY
- result_type operator()(const argument_type&) const { return 0; }
+ result_type operator()(const argument_type&) const {
+ return 66740831; // return a fundamentally attractive random value.
+ }
};
#endif // _LIBCPP_STD_VER > 14
OpenPOWER on IntegriCloud