From c6b3f2cf583d8fec124f9d70a172b513363506fe Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 13 Aug 2020 14:05:00 -0700 Subject: Export of internal Abseil changes -- 0c8282d75798c77733eee6167870bcc6acc0bfc1 by Evan Brown : Provide mutable access to the key in node handles using std::launder when compiled with C++17 or later. Also, document why we can't provide mutable access to the key without C++17. Note: we use Policy::mutable_key() because btree already uses Policy::key() internally to get const key access, and we want to avoid calling std::launder unless we need mutable access to the key. PiperOrigin-RevId: 326519000 -- 8018d0c3044400f0a731b0d2d00b606742c98818 by Xiaoyi Zhang : Move `Status` internal symbols from the public header into an internal header file. PiperOrigin-RevId: 326471847 -- 87a7644864ba7c003b0611898aaba1b71c840376 by Abseil Team : Avoid a costly divide (the division accounts for 10% of the time spent in the function). When the division is signed, the compiler has to generate a div. When it is unsigned, it can generate a shift: https://godbolt.org/z/vGfTv4. As per the test above the div, we know that the value is unsigned. PiperOrigin-RevId: 326453275 GitOrigin-RevId: 0c8282d75798c77733eee6167870bcc6acc0bfc1 Change-Id: I0a953558358055ab3dc6a533d8930698509b1195 --- absl/container/internal/common.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'absl/container/internal/common.h') diff --git a/absl/container/internal/common.h b/absl/container/internal/common.h index 8990f294..030e9d4a 100644 --- a/absl/container/internal/common.h +++ b/absl/container/internal/common.h @@ -146,8 +146,11 @@ class node_handle decltype(PolicyTraits::key(std::declval())) { - return PolicyTraits::key(this->slot()); + // When C++17 is available, we can use std::launder to provide mutable + // access to the key. Otherwise, we provide const access. + auto key() const + -> decltype(PolicyTraits::mutable_key(std::declval())) { + return PolicyTraits::mutable_key(this->slot()); } mapped_type& mapped() const { -- cgit v1.2.3