diff options
author | Henrik Gramner <gramner@twoorioles.com> | 2022-04-28 03:53:52 +0300 |
---|---|---|
committer | Henrik Gramner <henrik@gramner.com> | 2022-04-28 03:53:52 +0300 |
commit | 8bb0655895f9457ab5157f92adf311d9bd5e2801 (patch) | |
tree | a134f5f297fb302eabe24b5a66ff73d8d088ad84 | |
parent | ffb59680356fd210816cf9e46d9d023ade1f4d5a (diff) |
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.
-rw-r--r-- | src/ref.c | 6 | ||||
-rw-r--r-- | src/ref.h | 6 |
2 files changed, 5 insertions, 7 deletions
@@ -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) { @@ -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 */ |