Skip to content

Commit 4055086

Browse files
MarcoFalkePastaPastaPasta
MarcoFalke
authored andcommitted
Merge bitcoin#17218: Replace the LogPrint function with a macro
8734c85 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 bitcoin#14209. The decision to revert is discussed in bitcoin#16688, which adds verbose logging for validation event notification. ACKs for top commit: jnewbery: ACK 8734c85 Tree-SHA512: 19e995eaef0ff008a9f8c1fd6f3882f1fbf6794dd7e2dcf5c68056be787eee198d2956037d4ffba2b01e7658b47eba276cd7132feede78832373b3304203961e
1 parent 507ff8d commit 4055086

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/logging.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ static inline void LogPrintf(const char* fmt, const Args&... args)
194194
}
195195
}
196196

197-
template <typename... Args>
198-
static inline void LogPrint(const BCLog::LogFlags& category, const Args&... args)
199-
{
200-
if (LogAcceptCategory((category))) {
201-
LogPrintf(args...);
202-
}
203-
}
197+
// Use a macro instead of a function for conditional logging to prevent
198+
// evaluating arguments when logging for the category is not enabled.
199+
#define LogPrint(category, ...) \
200+
do { \
201+
if (LogAcceptCategory((category))) { \
202+
LogPrintf(__VA_ARGS__); \
203+
} \
204+
} while (0)
204205

205206
#endif // BITCOIN_LOGGING_H

0 commit comments

Comments
 (0)