From 5eb939706b58d9ca9b3b1944d6f5ea086f4b8599 Mon Sep 17 00:00:00 2001 From: lihuiba Date: Thu, 21 Dec 2023 17:21:01 +0800 Subject: [PATCH] make DEFER() always inline --- common/utility.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/utility.h b/common/utility.h index afeb6fb0..33601371 100644 --- a/common/utility.h +++ b/common/utility.h @@ -74,12 +74,15 @@ ptr_array_t ptr_array(T* pbegin, size_t n) return {pbegin, pbegin + n}; } +#define __INLINE__ __attribute__((always_inline)) +#define __FORCE_INLINE__ __INLINE__ inline + template class Defer { public: - Defer(T fn) : m_func(fn) {} - ~Defer() { m_func(); } + Defer(T fn) __INLINE__ : m_func(fn) {} + ~Defer() __INLINE__ { m_func(); } void operator=(const Defer&) = delete; operator bool () { return true; } // if (DEFER(...)) { ... } @@ -87,12 +90,9 @@ class Defer T m_func; }; -template +template __INLINE__ Defer make_defer(T func) { return Defer(func); } -#define __INLINE__ __attribute__((always_inline)) -#define __FORCE_INLINE__ __INLINE__ inline - #define _CONCAT_(a, b) a##b #define _CONCAT(a, b) _CONCAT_(a, b)