From 2b7347d5773fc91475ce6a18e0e96b40f0b8cb94 Mon Sep 17 00:00:00 2001 From: David Young Date: Tue, 11 Feb 2020 10:52:48 -0600 Subject: Record the state of a log outlet on first use and reuse that state on subsequent hlog_fast() calls. While I'm here, add a typedef, hlog_outlet_t, for struct hlog_outlet, and use it. --- src/hlog.c | 8 ++++++-- src/hlog.h | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/hlog.c b/src/hlog.c index e27f539..a017843 100644 --- a/src/hlog.c +++ b/src/hlog.c @@ -261,8 +261,12 @@ hlog_impl(struct hlog_outlet *ls0, const char *fmt, ...) struct hlog_outlet *ls; va_list ap; - if ((ls = hlog_outlet_find_active(ls0)) == NULL) - return; + if ((ls = hlog_outlet_find_active(ls0)) == NULL) { + ls0->ls_resolved = HLOG_OUTLET_S_OFF; + return; + } + + ls0->ls_resolved = HLOG_OUTLET_S_ON; va_start(ap, fmt); vhlog(fmt, ap); diff --git a/src/hlog.h b/src/hlog.h index 2ac64d0..921ce64 100644 --- a/src/hlog.h +++ b/src/hlog.h @@ -53,6 +53,8 @@ struct hlog_outlet { TAILQ_ENTRY(hlog_outlet) ls_next; }; +typedef struct hlog_outlet hlog_outlet_t; + #define HLOG_CONSTRUCTOR(__sym) \ void hlog_constructor_##__sym(void) __constructor; \ void \ @@ -94,9 +96,14 @@ HLOG_OUTLET_DECL(all); #define hlog_fast(_name, ...) \ do { \ - struct hlog_outlet *_ls; \ - if ((_ls = hlog_outlet_find_active((&log_##_name))) != NULL) \ - hlog_always((_ls), __VA_ARGS__); \ + hlog_outlet_t *_ls0 = &log_##_name; \ + \ + if (_ls0->ls_resolved == HLOG_OUTLET_S_OFF) \ + break; \ + else if (_ls0->ls_resolved == HLOG_OUTLET_S_ON) \ + hlog_always(_ls0, __VA_ARGS__); \ + else \ + hlog_impl(_ls0, __VA_ARGS__); \ } while (/*CONSTCOND*/0) struct hlog_outlet *hlog_outlet_find_active(struct hlog_outlet *); -- cgit v0.12