From 8256a2d5a69eaf16af15a1e592b25b9a1eefb788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 6 Oct 2023 12:41:55 +0200 Subject: [PATCH] spa: remove unnecessary indirection for some `spa_log_topic`s This results in shorter machine code since it removes one pointer load and a NULL check. --- spa/plugins/alsa/alsa.c | 5 +++-- spa/plugins/alsa/alsa.h | 6 +++--- spa/plugins/audioconvert/audioadapter.c | 6 +++--- spa/plugins/audioconvert/audioconvert.c | 6 +++--- spa/plugins/audiomixer/audiomixer.c | 6 +++--- spa/plugins/audiomixer/mixer-dsp.c | 6 +++--- spa/plugins/avb/avb.c | 5 +++-- spa/plugins/avb/avb.h | 6 +++--- spa/plugins/libcamera/libcamera.c | 3 +-- spa/plugins/libcamera/libcamera.h | 6 +++--- spa/plugins/v4l2/v4l2.c | 5 +++-- spa/plugins/v4l2/v4l2.h | 8 +++++--- spa/plugins/videoconvert/videoadapter.c | 6 +++--- 13 files changed, 39 insertions(+), 35 deletions(-) diff --git a/spa/plugins/alsa/alsa.c b/spa/plugins/alsa/alsa.c index b003582f5..fad5183bc 100644 --- a/spa/plugins/alsa/alsa.c +++ b/spa/plugins/alsa/alsa.c @@ -9,6 +9,8 @@ #include #include +#include "alsa.h" + extern const struct spa_handle_factory spa_alsa_source_factory; extern const struct spa_handle_factory spa_alsa_sink_factory; extern const struct spa_handle_factory spa_alsa_udev_factory; @@ -20,8 +22,7 @@ extern const struct spa_handle_factory spa_alsa_compress_offload_sink_factory; extern const struct spa_handle_factory spa_alsa_compress_offload_device_factory; #endif -struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.alsa"); -struct spa_log_topic *alsa_log_topic = &log_topic; +struct spa_log_topic alsa_log_topic = SPA_LOG_TOPIC(0, "spa.alsa"); SPA_EXPORT int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index) diff --git a/spa/plugins/alsa/alsa.h b/spa/plugins/alsa/alsa.h index 150991905..611630a57 100644 --- a/spa/plugins/alsa/alsa.h +++ b/spa/plugins/alsa/alsa.h @@ -8,12 +8,12 @@ #include #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT alsa_log_topic -extern struct spa_log_topic *alsa_log_topic; +#define SPA_LOG_TOPIC_DEFAULT &alsa_log_topic +extern struct spa_log_topic alsa_log_topic; static inline void alsa_log_topic_init(struct spa_log *log) { - spa_log_topic_init(log, alsa_log_topic); + spa_log_topic_init(log, &alsa_log_topic); } #endif /* SPA_ALSA_H */ diff --git a/spa/plugins/audioconvert/audioadapter.c b/spa/plugins/audioconvert/audioadapter.c index 2750838ca..0aa252935 100644 --- a/spa/plugins/audioconvert/audioadapter.c +++ b/spa/plugins/audioconvert/audioadapter.c @@ -26,8 +26,8 @@ #include #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT log_topic -static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.audioadapter"); +#define SPA_LOG_TOPIC_DEFAULT &log_topic +static struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.audioadapter"); #define DEFAULT_ALIGN 16 @@ -1755,7 +1755,7 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); - spa_log_topic_init(this->log, log_topic); + spa_log_topic_init(this->log, &log_topic); this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU); diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index a6b367bc7..8dd0da8c6 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -36,8 +36,8 @@ #include "wavfile.h" #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT log_topic -static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.audioconvert"); +#define SPA_LOG_TOPIC_DEFAULT &log_topic +static struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.audioconvert"); #define DEFAULT_RATE 48000 #define DEFAULT_CHANNELS 2 @@ -3354,7 +3354,7 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); - spa_log_topic_init(this->log, log_topic); + spa_log_topic_init(this->log, &log_topic); this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU); if (this->cpu) { diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 40fc71d47..b191cbd9d 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -23,8 +23,8 @@ #include "mix-ops.h" #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT log_topic -static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.audiomixer"); +#define SPA_LOG_TOPIC_DEFAULT &log_topic +static struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.audiomixer"); #define DEFAULT_RATE 48000 #define DEFAULT_CHANNELS 2 @@ -918,7 +918,7 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); - spa_log_topic_init(this->log, log_topic); + spa_log_topic_init(this->log, &log_topic); this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop); if (this->data_loop == NULL) { diff --git a/spa/plugins/audiomixer/mixer-dsp.c b/spa/plugins/audiomixer/mixer-dsp.c index 31c585b57..c1911bae0 100644 --- a/spa/plugins/audiomixer/mixer-dsp.c +++ b/spa/plugins/audiomixer/mixer-dsp.c @@ -23,8 +23,8 @@ #include "mix-ops.h" #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT log_topic -static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.mixer-dsp"); +#define SPA_LOG_TOPIC_DEFAULT &log_topic +static struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.mixer-dsp"); #define MAX_BUFFERS 64 #define MAX_PORTS 512 @@ -855,7 +855,7 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); - spa_log_topic_init(this->log, log_topic); + spa_log_topic_init(this->log, &log_topic); this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop); if (this->data_loop == NULL) { diff --git a/spa/plugins/avb/avb.c b/spa/plugins/avb/avb.c index 8e5c7bb5f..71f95d86c 100644 --- a/spa/plugins/avb/avb.c +++ b/spa/plugins/avb/avb.c @@ -7,11 +7,12 @@ #include #include +#include "avb.h" + extern const struct spa_handle_factory spa_avb_sink_factory; extern const struct spa_handle_factory spa_avb_source_factory; -struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.avb"); -struct spa_log_topic *avb_log_topic = &log_topic; +struct spa_log_topic avb_log_topic = SPA_LOG_TOPIC(0, "spa.avb"); SPA_EXPORT int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index) diff --git a/spa/plugins/avb/avb.h b/spa/plugins/avb/avb.h index 623747627..e6cbf41bc 100644 --- a/spa/plugins/avb/avb.h +++ b/spa/plugins/avb/avb.h @@ -8,12 +8,12 @@ #include #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT avb_log_topic -extern struct spa_log_topic *avb_log_topic; +#define SPA_LOG_TOPIC_DEFAULT &avb_log_topic +extern struct spa_log_topic avb_log_topic; static inline void avb_log_topic_init(struct spa_log *log) { - spa_log_topic_init(log, avb_log_topic); + spa_log_topic_init(log, &avb_log_topic); } #endif /* SPA_AVB_H */ diff --git a/spa/plugins/libcamera/libcamera.c b/spa/plugins/libcamera/libcamera.c index ca67a49b6..d9b317bc7 100644 --- a/spa/plugins/libcamera/libcamera.c +++ b/spa/plugins/libcamera/libcamera.c @@ -9,8 +9,7 @@ #include "libcamera.h" -struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.libcamera"); -struct spa_log_topic *libcamera_log_topic = &log_topic; +struct spa_log_topic libcamera_log_topic = SPA_LOG_TOPIC(0, "spa.libcamera"); SPA_EXPORT int spa_handle_factory_enum(const struct spa_handle_factory **factory, diff --git a/spa/plugins/libcamera/libcamera.h b/spa/plugins/libcamera/libcamera.h index a022ea97f..7d279819a 100644 --- a/spa/plugins/libcamera/libcamera.h +++ b/spa/plugins/libcamera/libcamera.h @@ -18,12 +18,12 @@ extern const struct spa_handle_factory spa_libcamera_manager_factory; extern const struct spa_handle_factory spa_libcamera_device_factory; #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT libcamera_log_topic -extern struct spa_log_topic *libcamera_log_topic; +#define SPA_LOG_TOPIC_DEFAULT &libcamera_log_topic +extern struct spa_log_topic libcamera_log_topic; static inline void libcamera_log_topic_init(struct spa_log *log) { - spa_log_topic_init(log, libcamera_log_topic); + spa_log_topic_init(log, &libcamera_log_topic); } #ifdef __cplusplus diff --git a/spa/plugins/v4l2/v4l2.c b/spa/plugins/v4l2/v4l2.c index cb9f37455..69bd7272a 100644 --- a/spa/plugins/v4l2/v4l2.c +++ b/spa/plugins/v4l2/v4l2.c @@ -7,12 +7,13 @@ #include #include +#include "v4l2.h" + extern const struct spa_handle_factory spa_v4l2_source_factory; extern const struct spa_handle_factory spa_v4l2_udev_factory; extern const struct spa_handle_factory spa_v4l2_device_factory; -struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.v4l2"); -struct spa_log_topic *v4l2_log_topic = &log_topic; +struct spa_log_topic v4l2_log_topic = SPA_LOG_TOPIC(0, "spa.v4l2"); SPA_EXPORT int spa_handle_factory_enum(const struct spa_handle_factory **factory, diff --git a/spa/plugins/v4l2/v4l2.h b/spa/plugins/v4l2/v4l2.h index 0d5c1482a..04065e63e 100644 --- a/spa/plugins/v4l2/v4l2.h +++ b/spa/plugins/v4l2/v4l2.h @@ -4,15 +4,17 @@ #include +#include + #include #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT v4l2_log_topic -extern struct spa_log_topic *v4l2_log_topic; +#define SPA_LOG_TOPIC_DEFAULT &v4l2_log_topic +extern struct spa_log_topic v4l2_log_topic; static inline void v4l2_log_topic_init(struct spa_log *log) { - spa_log_topic_init(log, v4l2_log_topic); + spa_log_topic_init(log, &v4l2_log_topic); } struct spa_v4l2_device { diff --git a/spa/plugins/videoconvert/videoadapter.c b/spa/plugins/videoconvert/videoadapter.c index 113551821..585964e33 100644 --- a/spa/plugins/videoconvert/videoadapter.c +++ b/spa/plugins/videoconvert/videoadapter.c @@ -25,8 +25,8 @@ #include #undef SPA_LOG_TOPIC_DEFAULT -#define SPA_LOG_TOPIC_DEFAULT log_topic -static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.videoadapter"); +#define SPA_LOG_TOPIC_DEFAULT &log_topic +static struct spa_log_topic log_topic = SPA_LOG_TOPIC(0, "spa.videoadapter"); #define DEFAULT_ALIGN 16 @@ -1554,7 +1554,7 @@ impl_init(const struct spa_handle_factory *factory, this = (struct impl *) handle; this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); - spa_log_topic_init(this->log, log_topic); + spa_log_topic_init(this->log, &log_topic); this->cpu = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU);