summaryrefslogtreecommitdiff
path: root/AK/Format.h
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2021-02-24 02:05:43 +0330
committerAndreas Kling <kling@serenityos.org>2021-02-24 13:07:28 +0100
commit857cdee0d0e88a2681126ce564b61ad337a7f898 (patch)
tree2e706b9a395f75af01dfa3b99c793424c1f645d6 /AK/Format.h
parent71de5433f8b2c97ccc289b656a626b070b744a47 (diff)
downloadserenity-857cdee0d0e88a2681126ce564b61ad337a7f898.zip
AK: Make dbgln_if() avoid evaluating the arguments when disabled
Naturally, this makes the `enabled` flag on dbgln() obsolete.
Diffstat (limited to 'AK/Format.h')
-rw-r--r--AK/Format.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/AK/Format.h b/AK/Format.h
index c5b6ce795e..c7b5400e30 100644
--- a/AK/Format.h
+++ b/AK/Format.h
@@ -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)