1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:17:45 +00:00

AK: Make dbgln_if() avoid evaluating the arguments when disabled

Naturally, this makes the `enabled` flag on dbgln() obsolete.
This commit is contained in:
AnotherTest 2021-02-24 02:05:43 +03:30 committed by Andreas Kling
parent 71de5433f8
commit 857cdee0d0
3 changed files with 10 additions and 8 deletions

View file

@ -396,15 +396,13 @@ inline void warnln() { outln(stderr); }
void vdbgln(StringView fmtstr, TypeErasedFormatParams);
template<bool enabled = true, typename... Parameters>
template<typename... Parameters>
void dbgln(CheckedFormatString<Parameters...>&& fmtstr, const Parameters&... parameters)
{
if constexpr (enabled)
vdbgln(fmtstr.view(), VariadicFormatParams { parameters... });
vdbgln(fmtstr.view(), VariadicFormatParams { parameters... });
}
template<bool enabled = true>
void dbgln() { dbgln<enabled>(""); }
inline void dbgln() { dbgln(""); }
void set_debug_enabled(bool);
@ -488,4 +486,8 @@ using AK::CheckedFormatString;
using AK::FormatIfSupported;
using AK::FormatString;
#define dbgln_if(flag, fmt, ...) dbgln<flag>(fmt, ##__VA_ARGS__)
#define dbgln_if(flag, fmt, ...) \
do { \
if constexpr (flag) \
dbgln(fmt, ##__VA_ARGS__); \
} while (0)