Extract at()'s throw_exception calls into noinline function (#223)

* Create function `detail::throw_out_of_range()` to make `at()` more inlineable

* Replace `boost::throw_exception()` with `detail::throw_out_of_range()`
This commit is contained in:
Braden Ganetsky
2023-12-19 10:08:08 -06:00
committed by GitHub
parent f493603f5c
commit 0d2751c5e1
4 changed files with 57 additions and 26 deletions

View File

@ -0,0 +1,30 @@
// Copyright (C) 2023 Braden Ganetsky
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_UNORDERED_DETAIL_THROW_EXCEPTION_HPP
#define BOOST_UNORDERED_DETAIL_THROW_EXCEPTION_HPP
#include <boost/config.hpp>
#if defined(BOOST_HAS_PRAGMA_ONCE)
#pragma once
#endif
#include <boost/throw_exception.hpp>
#include <stdexcept>
namespace boost {
namespace unordered {
namespace detail {
BOOST_NOINLINE BOOST_NORETURN inline void throw_out_of_range(
char const* message)
{
boost::throw_exception(std::out_of_range(message));
}
} // namespace detail
} // namespace unordered
} // namespace boost
#endif // BOOST_UNORDERED_DETAIL_THROW_EXCEPTION_HPP

View File

@ -14,12 +14,12 @@
#include <boost/unordered/detail/foa/flat_map_types.hpp>
#include <boost/unordered/detail/foa/table.hpp>
#include <boost/unordered/detail/serialize_container.hpp>
#include <boost/unordered/detail/throw_exception.hpp>
#include <boost/unordered/detail/type_traits.hpp>
#include <boost/unordered/unordered_flat_map_fwd.hpp>
#include <boost/core/allocator_access.hpp>
#include <boost/container_hash/hash.hpp>
#include <boost/throw_exception.hpp>
#include <initializer_list>
#include <iterator>
@ -459,8 +459,8 @@ namespace boost {
// TODO: someday refactor this to conditionally serialize the key and
// include it in the error message
//
boost::throw_exception(
std::out_of_range("key was not found in unordered_flat_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_flat_map");
}
mapped_type const& at(key_type const& key) const
@ -469,8 +469,8 @@ namespace boost {
if (pos != table_.end()) {
return pos->second;
}
boost::throw_exception(
std::out_of_range("key was not found in unordered_flat_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_flat_map");
}
template <class K>
@ -483,8 +483,8 @@ namespace boost {
if (pos != table_.end()) {
return pos->second;
}
boost::throw_exception(
std::out_of_range("key was not found in unordered_flat_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_flat_map");
}
template <class K>
@ -497,8 +497,8 @@ namespace boost {
if (pos != table_.end()) {
return pos->second;
}
boost::throw_exception(
std::out_of_range("key was not found in unordered_flat_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_flat_map");
}
BOOST_FORCEINLINE mapped_type& operator[](key_type const& key)

View File

@ -16,6 +16,7 @@
#include <boost/unordered/detail/map.hpp>
#include <boost/unordered/detail/serialize_fca_container.hpp>
#include <boost/unordered/detail/throw_exception.hpp>
#include <boost/unordered/detail/type_traits.hpp>
#include <boost/container_hash/hash.hpp>
@ -1586,8 +1587,8 @@ namespace boost {
return p->value().second;
}
boost::throw_exception(
std::out_of_range("Unable to find key in unordered_map."));
boost::unordered::detail::throw_out_of_range(
"Unable to find key in unordered_map.");
}
template <class K, class T, class H, class P, class A>
@ -1602,8 +1603,8 @@ namespace boost {
return p->value().second;
}
boost::throw_exception(
std::out_of_range("Unable to find key in unordered_map."));
boost::unordered::detail::throw_out_of_range(
"Unable to find key in unordered_map.");
}
template <class K, class T, class H, class P, class A>
@ -1620,8 +1621,8 @@ namespace boost {
return p->value().second;
}
boost::throw_exception(
std::out_of_range("Unable to find key in unordered_map."));
boost::unordered::detail::throw_out_of_range(
"Unable to find key in unordered_map.");
}
template <class K, class T, class H, class P, class A>
@ -1638,8 +1639,8 @@ namespace boost {
return p->value().second;
}
boost::throw_exception(
std::out_of_range("Unable to find key in unordered_map."));
boost::unordered::detail::throw_out_of_range(
"Unable to find key in unordered_map.");
}
template <class K, class T, class H, class P, class A>

View File

@ -15,12 +15,12 @@
#include <boost/unordered/detail/foa/node_map_types.hpp>
#include <boost/unordered/detail/foa/table.hpp>
#include <boost/unordered/detail/serialize_container.hpp>
#include <boost/unordered/detail/throw_exception.hpp>
#include <boost/unordered/detail/type_traits.hpp>
#include <boost/unordered/unordered_node_map_fwd.hpp>
#include <boost/core/allocator_access.hpp>
#include <boost/container_hash/hash.hpp>
#include <boost/throw_exception.hpp>
#include <initializer_list>
#include <iterator>
@ -554,8 +554,8 @@ namespace boost {
// TODO: someday refactor this to conditionally serialize the key and
// include it in the error message
//
boost::throw_exception(
std::out_of_range("key was not found in unordered_node_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_node_map");
}
mapped_type const& at(key_type const& key) const
@ -564,8 +564,8 @@ namespace boost {
if (pos != table_.end()) {
return pos->second;
}
boost::throw_exception(
std::out_of_range("key was not found in unordered_node_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_node_map");
}
template <class K>
@ -578,8 +578,8 @@ namespace boost {
if (pos != table_.end()) {
return pos->second;
}
boost::throw_exception(
std::out_of_range("key was not found in unordered_node_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_node_map");
}
template <class K>
@ -592,8 +592,8 @@ namespace boost {
if (pos != table_.end()) {
return pos->second;
}
boost::throw_exception(
std::out_of_range("key was not found in unordered_node_map"));
boost::unordered::detail::throw_out_of_range(
"key was not found in unordered_node_map");
}
BOOST_FORCEINLINE mapped_type& operator[](key_type const& key)