0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-08 14:34:53 -05:00

Replace the LogPrint function with a macro

Calling LogPrint with a category that is not enabled results in
evaluating the remaining function arguments, which may be arbitrarily
complex (and possibly expensive) expressions. Defining LogPrint as a
macro prevents this unnecessary expression evaluation.

This is a partial revert of #14209. The decision to revert is discussed
in #16688, which adds verbose logging for validation event notification.
This commit is contained in:
Jeffrey Czyz 2019-10-22 10:06:02 -07:00
parent b499d8576f
commit 8734c856f8

View file

@ -155,12 +155,13 @@ static inline void LogPrintf(const char* fmt, const Args&... args)
} }
} }
template <typename... Args> // Use a macro instead of a function for conditional logging to prevent
static inline void LogPrint(const BCLog::LogFlags& category, const Args&... args) // evaluating arguments when logging for the category is not enabled.
{ #define LogPrint(category, ...) \
if (LogAcceptCategory((category))) { do { \
LogPrintf(args...); if (LogAcceptCategory((category))) { \
} LogPrintf(__VA_ARGS__); \
} } \
} while (0)
#endif // BITCOIN_LOGGING_H #endif // BITCOIN_LOGGING_H