From c70620128203c3d707ce30bbe164e3621f4ca1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 6 Jun 2026 22:52:55 +0800 Subject: [PATCH] Global: adds some `always_inline` --- src/common/io.h | 42 ++++++++++++++++----------------------- src/common/mallocHelper.h | 2 ++ src/common/strutil.h | 11 ++++++++++ 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/common/io.h b/src/common/io.h index f7aec0b42..e31712061 100644 --- a/src/common/io.h +++ b/src/common/io.h @@ -40,6 +40,7 @@ HANDLE openat(HANDLE dfd, const char* fileName, int oflag); HANDLE openatW(HANDLE dfd, const wchar_t* fileName, uint16_t fileNameLen, bool directory); #endif +FF_A_ALWAYS_INLINE static inline bool ffIsValidNativeFD(FFNativeFD fd) { #ifndef _WIN32 return fd >= 0; @@ -49,20 +50,17 @@ static inline bool ffIsValidNativeFD(FFNativeFD fd) { #endif } -FF_A_NONNULL(1) static inline bool wrapClose(FFNativeFD* pfd) { +FF_A_ALWAYS_INLINE FF_A_NONNULL(1) +static inline void wrapClose(FFNativeFD* pfd) { assert(pfd); - if (!ffIsValidNativeFD(*pfd)) { - return false; - } - + if (ffIsValidNativeFD(*pfd)) { #ifndef _WIN32 - close(*pfd); + close(*pfd); #else - NtClose(*pfd); + NtClose(*pfd); #endif - - return true; + } } #define FF_AUTO_CLOSE_FD FF_A_CLEANUP(wrapClose) @@ -250,34 +248,28 @@ static inline void ffUnsuppressIO(bool* suppressed) { void ffListFilesRecursively(const char* path, bool pretty); -FF_A_NONNULL(1) static inline bool wrapFclose(FILE** pfile) { +FF_A_NONNULL(1) FF_A_ALWAYS_INLINE static inline void wrapFclose(FILE** pfile) { assert(pfile); - if (!*pfile) { - return false; + if (*pfile) { + fclose(*pfile); } - fclose(*pfile); - return true; } #define FF_AUTO_CLOSE_FILE FF_A_CLEANUP(wrapFclose) -FF_A_NONNULL(1) +FF_A_NONNULL(1) FF_A_ALWAYS_INLINE #ifndef _WIN32 -static inline bool wrapClosedir(DIR** pdir) { +static inline void wrapClosedir(DIR** pdir) { assert(pdir); - if (!*pdir) { - return false; + if (*pdir) { + closedir(*pdir); } - closedir(*pdir); - return true; } #else -static inline bool wrapClosedir(HANDLE* pdir) { +static inline void wrapClosedir(HANDLE* pdir) { assert(pdir); - if (!*pdir) { - return false; + if (*pdir) { + FindClose(*pdir); } - FindClose(*pdir); - return true; } #endif #define FF_AUTO_CLOSE_DIR FF_A_CLEANUP(wrapClosedir) diff --git a/src/common/mallocHelper.h b/src/common/mallocHelper.h index 5b24df471..a13011838 100644 --- a/src/common/mallocHelper.h +++ b/src/common/mallocHelper.h @@ -2,6 +2,7 @@ #include #include +#include "common/attributes.h" #if FF_HAVE_MALLOC_USABLE_SIZE || FF_HAVE_MSVC_MSIZE #if __has_include() @@ -13,6 +14,7 @@ #include #endif +FF_A_ALWAYS_INLINE FF_A_NONNULL(1) static inline void ffWrapFree(const void* pPtr) { assert(pPtr); if (*(void**) pPtr) { diff --git a/src/common/strutil.h b/src/common/strutil.h index 00a8a0839..f21528fb5 100644 --- a/src/common/strutil.h +++ b/src/common/strutil.h @@ -5,6 +5,7 @@ #include #include +#include "common/attributes.h" #include "common/wcwidth.h" #ifdef _WIN32 @@ -25,14 +26,17 @@ static inline bool ffStrSet(const char* str) { return *str != '\0'; } +FF_A_ALWAYS_INLINE static inline bool ffStrStartsWithIgnCase(const char* str, const char* compareTo) { return strncasecmp(str, compareTo, strlen(compareTo)) == 0; } +FF_A_ALWAYS_INLINE static inline bool ffStrEqualsIgnCase(const char* str, const char* compareTo) { return strcasecmp(str, compareTo) == 0; } +FF_A_ALWAYS_INLINE static inline bool ffStrStartsWith(const char* str, const char* compareTo) { return strncmp(str, compareTo, strlen(compareTo)) == 0; } @@ -55,26 +59,32 @@ static inline bool ffStrEndsWithIgnCase(const char* str, const char* compareTo) return strncasecmp(str + strLength - compareToLength, compareTo, compareToLength) == 0; } +FF_A_ALWAYS_INLINE static inline bool ffStrEquals(const char* str, const char* compareTo) { return strcmp(str, compareTo) == 0; } +FF_A_ALWAYS_INLINE static inline bool ffStrContains(const char* str, const char* compareTo) { return strstr(str, compareTo) != NULL; } +FF_A_ALWAYS_INLINE static inline bool ffStrContainsIgnCase(const char* str, const char* compareTo) { return strcasestr(str, compareTo) != NULL; } +FF_A_ALWAYS_INLINE static inline bool ffStrContainsC(const char* str, char compareTo) { return strchr(str, compareTo) != NULL; } +FF_A_ALWAYS_INLINE static inline bool ffCharIsEnglishAlphabet(char c) { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); } +FF_A_ALWAYS_INLINE static inline bool ffCharIsDigit(char c) { return '0' <= c && c <= '9'; } @@ -86,6 +96,7 @@ uint8_t ffUtf8CharLenWidth(const char* str, uint32_t length, uint8_t* width); uint32_t ffUtf8StrWidth(const char* str, uint32_t length); +FF_A_ALWAYS_INLINE static inline bool ffCharIsHexDigit(char c) { return ffCharIsDigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); }