mirror of
https://github.com/nlohmann/json.git
synced 2026-10-16 03:07:12 +00:00
Construct remaining hot-path exceptions out of line so core functions inline (#5838)
* Construct remaining hot-path exceptions out of line so core functions inline Signed-off-by: Niels Lohmann <mail@nlohmann.me> * Move throw_key_not_found() before at_impl()'s comment block Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
1 parent
91869983a0
commit
6a27b9acb2
6 files changed
+276
-72
No files matched your search
@@ -90,6 +90,15 @@ private:
|
||||
return self.end();
|
||||
}
|
||||
|
||||
/// @brief throw the exception of a failed at() lookup
|
||||
/// @note kept out of line so that at_impl() stays small enough to inline
|
||||
/// @throw std::out_of_range always
|
||||
JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE
|
||||
static void throw_key_not_found()
|
||||
{
|
||||
JSON_THROW(std::out_of_range("key not found"));
|
||||
}
|
||||
|
||||
/// @brief shared implementation of the const and non-const at() overloads
|
||||
/// @throw std::out_of_range if @a key is not found
|
||||
template<typename Self, typename KeyType>
|
||||
@@ -98,7 +107,7 @@ private:
|
||||
const auto it = find_impl(self, key);
|
||||
if (it == self.end())
|
||||
{
|
||||
JSON_THROW(std::out_of_range("key not found"));
|
||||
throw_key_not_found();
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user