Commit 10f5670b authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Avoid duplicating throw_exception instances taking string literal

Summary: [Folly] Avoid duplicating throw_exception instances taking string literal, which differ only in the length of the string literal.

Reviewed By: marshallcline

Differential Revision: D7853216

fbshipit-source-id: a4648952cc10661322e5e23c6317ba4b75c268fb
parent 9a33b9b1
......@@ -36,13 +36,35 @@ template <typename Ex>
#endif
}
// clang-format off
namespace detail {
template <typename T>
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN T&& to_exception_arg_(T&& t) {
return static_cast<T&&>(t);
}
template <std::size_t N>
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN char const* to_exception_arg_(
char const (&array)[N]) {
return static_cast<char const*>(array);
}
template <typename Ex, typename... Args>
[[noreturn]] FOLLY_NOINLINE FOLLY_COLD void throw_exception_(Args&&... args) {
throw_exception(Ex(static_cast<Args&&>(args)...));
}
} // namespace detail
// clang-format on
/// throw_exception
///
/// Construct and throw an exception if exceptions are enabled, or terminate if
/// compiled with -fno-exceptions.
///
/// Converts any arguments of type `char const[N]` to `char const*`.
template <typename Ex, typename... Args>
[[noreturn]] FOLLY_NOINLINE FOLLY_COLD void throw_exception(Args&&... args) {
throw_exception(Ex(static_cast<Args&&>(args)...));
[[noreturn]] FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN void
throw_exception(Args&&... args) {
detail::throw_exception_<Ex>(
detail::to_exception_arg_(static_cast<Args&&>(args))...);
}
} // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment