From 8bb0655895f9457ab5157f92adf311d9bd5e2801 Mon Sep 17 00:00:00 2001 From: Henrik Gramner Date: Thu, 28 Apr 2022 02:53:52 +0200 Subject: Inline dav1d_ref_inc() Avoids the function call overhead in non-LTO builds. Also reorder code in dav1d_ref_dec() to enable tail call elimination. --- src/ref.c | 6 +----- src/ref.h | 6 ++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ref.c b/src/ref.c index 3889cba..46462b4 100644 --- a/src/ref.c +++ b/src/ref.c @@ -88,22 +88,18 @@ Dav1dRef *dav1d_ref_wrap(const uint8_t *const ptr, return res; } -void dav1d_ref_inc(Dav1dRef *const ref) { - atomic_fetch_add(&ref->ref_cnt, 1); -} - void dav1d_ref_dec(Dav1dRef **const pref) { assert(pref != NULL); Dav1dRef *const ref = *pref; if (!ref) return; + *pref = NULL; if (atomic_fetch_sub(&ref->ref_cnt, 1) == 1) { const int free_ref = ref->free_ref; ref->free_callback(ref->const_data, ref->user_data); if (free_ref) free(ref); } - *pref = NULL; } int dav1d_ref_is_writable(Dav1dRef *const ref) { diff --git a/src/ref.h b/src/ref.h index 54f5f69..f6e3028 100644 --- a/src/ref.h +++ b/src/ref.h @@ -50,9 +50,11 @@ Dav1dRef *dav1d_ref_create_using_pool(Dav1dMemPool *pool, size_t size); Dav1dRef *dav1d_ref_wrap(const uint8_t *ptr, void (*free_callback)(const uint8_t *data, void *user_data), void *user_data); -void dav1d_ref_inc(Dav1dRef *ref); void dav1d_ref_dec(Dav1dRef **ref); - int dav1d_ref_is_writable(Dav1dRef *ref); +static inline void dav1d_ref_inc(Dav1dRef *const ref) { + atomic_fetch_add(&ref->ref_cnt, 1); +} + #endif /* DAV1D_SRC_REF_H */ -- cgit v1.2.3