mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Merge #17218: Replace the LogPrint function with a macro
8734c856f8
Replace the LogPrint function with a macro (Jeffrey Czyz) Pull request description: 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. ACKs for top commit: jnewbery: ACK8734c856f8
Tree-SHA512: 19e995eaef0ff008a9f8c1fd6f3882f1fbf6794dd7e2dcf5c68056be787eee198d2956037d4ffba2b01e7658b47eba276cd7132feede78832373b3304203961e
This commit is contained in:
commit
90a2341713
1 changed files with 8 additions and 7 deletions
|
@ -155,12 +155,13 @@ static inline void LogPrintf(const char* fmt, const Args&... args)
|
|||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
static inline void LogPrint(const BCLog::LogFlags& category, const Args&... args)
|
||||
{
|
||||
if (LogAcceptCategory((category))) {
|
||||
LogPrintf(args...);
|
||||
}
|
||||
}
|
||||
// Use a macro instead of a function for conditional logging to prevent
|
||||
// evaluating arguments when logging for the category is not enabled.
|
||||
#define LogPrint(category, ...) \
|
||||
do { \
|
||||
if (LogAcceptCategory((category))) { \
|
||||
LogPrintf(__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif // BITCOIN_LOGGING_H
|
||||
|
|
Loading…
Add table
Reference in a new issue