diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2024-11-01 21:52:37 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2024-11-13 20:21:39 +0000 |
commit | e717c322c6ee21bd5d9cf9373dcd9b4e8ba3312f (patch) | |
tree | 7eb96eb237f6c4e6cf91775b5effcb0a1f63113c | |
parent | 37b17388fca498cff718a13aa8d4523f15427c8c (diff) | |
download | gcc-e717c322c6ee21bd5d9cf9373dcd9b4e8ba3312f.zip gcc-e717c322c6ee21bd5d9cf9373dcd9b4e8ba3312f.tar.gz gcc-e717c322c6ee21bd5d9cf9373dcd9b4e8ba3312f.tar.bz2 |
libstdc++: Replace _Hashtable::__fwd_value_for with cast
We can just use a cast to the appropriate type instead of calling a
function to do it. This gives the compiler less work to compile and
optimize, and at -O0 avoids a function call per element.
libstdc++-v3/ChangeLog:
* include/bits/hashtable.h (_Hashtable::__fwd_value_for):
Remove.
(_Hashtable::_M_assign): Use static_cast instead of
__fwd_value_for.
Reviewed-by: François Dumont <fdumont@gcc.gnu.org>
-rw-r--r-- | libstdc++-v3/include/bits/hashtable.h | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index bf6eed7..f1c3089 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -325,13 +325,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __node_ptr _M_node; }; - template<typename _Ht> - static constexpr - __conditional_t<std::is_lvalue_reference<_Ht>::value, - const value_type&, value_type&&> - __fwd_value_for(value_type& __val) noexcept - { return std::move(__val); } - // Compile-time diagnostics. // _Hash_code_base has everything protected, so use this derived type to @@ -1406,11 +1399,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (!__ht._M_before_begin._M_nxt) return; + using _FromVal = __conditional_t<is_lvalue_reference<_Ht>::value, + const value_type&, value_type&&>; + // First deal with the special first node pointed to by // _M_before_begin. __node_ptr __ht_n = __ht._M_begin(); __node_ptr __this_n - = __node_gen(__fwd_value_for<_Ht>(__ht_n->_M_v())); + = __node_gen(static_cast<_FromVal>(__ht_n->_M_v())); this->_M_copy_code(*__this_n, *__ht_n); _M_update_bbegin(__this_n); @@ -1418,7 +1414,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __node_ptr __prev_n = __this_n; for (__ht_n = __ht_n->_M_next(); __ht_n; __ht_n = __ht_n->_M_next()) { - __this_n = __node_gen(__fwd_value_for<_Ht>(__ht_n->_M_v())); + __this_n = __node_gen(static_cast<_FromVal>(__ht_n->_M_v())); __prev_n->_M_nxt = __this_n; this->_M_copy_code(*__this_n, *__ht_n); size_type __bkt = _M_bucket_index(*__this_n); |