AK: Make dbgln_if() avoid evaluating the arguments when disabled
Naturally, this makes the `enabled` flag on dbgln() obsolete.
This commit is contained in:
parent
71de5433f8
commit
857cdee0d0
Notes:
sideshowbarker
2024-07-18 21:57:52 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/857cdee0d0e Pull-request: https://github.com/SerenityOS/serenity/pull/5489 Reviewed-by: https://github.com/bgianfo
3 changed files with 10 additions and 8 deletions
14
AK/Format.h
14
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)
|
||||
|
|
|
@ -714,7 +714,7 @@ void Parser::error(StringView message)
|
|||
m_tokens[m_state.token_index].m_start.column);
|
||||
}
|
||||
m_errors.append(formatted_message);
|
||||
dbgln<CPP_DEBUG>("{}", formatted_message);
|
||||
dbgln_if(CPP_DEBUG, "{}", formatted_message);
|
||||
}
|
||||
|
||||
bool Parser::match_expression()
|
||||
|
|
|
@ -589,7 +589,7 @@ bool WindowManager::process_ongoing_window_resize(const MouseEvent& event, Windo
|
|||
|
||||
auto max_rect = maximized_window_rect(*m_resize_window);
|
||||
if (event.y() > max_rect.bottom()) {
|
||||
dbgln<RESIZE_DEBUG>("Should Maximize vertically");
|
||||
dbgln_if(RESIZE_DEBUG, "Should Maximize vertically");
|
||||
m_resize_window->set_vertically_maximized();
|
||||
m_resize_window = nullptr;
|
||||
m_resizing_mouse_button = MouseButton::None;
|
||||
|
|
Loading…
Add table
Reference in a new issue