Skip to content

Commit c706201

Browse files
committed
Global: adds some always_inline
1 parent e24e3b6 commit c706201

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

src/common/io.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ HANDLE openat(HANDLE dfd, const char* fileName, int oflag);
4040
HANDLE openatW(HANDLE dfd, const wchar_t* fileName, uint16_t fileNameLen, bool directory);
4141
#endif
4242

43+
FF_A_ALWAYS_INLINE
4344
static inline bool ffIsValidNativeFD(FFNativeFD fd) {
4445
#ifndef _WIN32
4546
return fd >= 0;
@@ -49,20 +50,17 @@ static inline bool ffIsValidNativeFD(FFNativeFD fd) {
4950
#endif
5051
}
5152

52-
FF_A_NONNULL(1) static inline bool wrapClose(FFNativeFD* pfd) {
53+
FF_A_ALWAYS_INLINE FF_A_NONNULL(1)
54+
static inline void wrapClose(FFNativeFD* pfd) {
5355
assert(pfd);
5456

55-
if (!ffIsValidNativeFD(*pfd)) {
56-
return false;
57-
}
58-
57+
if (ffIsValidNativeFD(*pfd)) {
5958
#ifndef _WIN32
60-
close(*pfd);
59+
close(*pfd);
6160
#else
62-
NtClose(*pfd);
61+
NtClose(*pfd);
6362
#endif
64-
65-
return true;
63+
}
6664
}
6765
#define FF_AUTO_CLOSE_FD FF_A_CLEANUP(wrapClose)
6866

@@ -250,34 +248,28 @@ static inline void ffUnsuppressIO(bool* suppressed) {
250248

251249
void ffListFilesRecursively(const char* path, bool pretty);
252250

253-
FF_A_NONNULL(1) static inline bool wrapFclose(FILE** pfile) {
251+
FF_A_NONNULL(1) FF_A_ALWAYS_INLINE static inline void wrapFclose(FILE** pfile) {
254252
assert(pfile);
255-
if (!*pfile) {
256-
return false;
253+
if (*pfile) {
254+
fclose(*pfile);
257255
}
258-
fclose(*pfile);
259-
return true;
260256
}
261257
#define FF_AUTO_CLOSE_FILE FF_A_CLEANUP(wrapFclose)
262258

263-
FF_A_NONNULL(1)
259+
FF_A_NONNULL(1) FF_A_ALWAYS_INLINE
264260
#ifndef _WIN32
265-
static inline bool wrapClosedir(DIR** pdir) {
261+
static inline void wrapClosedir(DIR** pdir) {
266262
assert(pdir);
267-
if (!*pdir) {
268-
return false;
263+
if (*pdir) {
264+
closedir(*pdir);
269265
}
270-
closedir(*pdir);
271-
return true;
272266
}
273267
#else
274-
static inline bool wrapClosedir(HANDLE* pdir) {
268+
static inline void wrapClosedir(HANDLE* pdir) {
275269
assert(pdir);
276-
if (!*pdir) {
277-
return false;
270+
if (*pdir) {
271+
FindClose(*pdir);
278272
}
279-
FindClose(*pdir);
280-
return true;
281273
}
282274
#endif
283275
#define FF_AUTO_CLOSE_DIR FF_A_CLEANUP(wrapClosedir)

src/common/mallocHelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <stdlib.h>
44
#include <assert.h>
5+
#include "common/attributes.h"
56

67
#if FF_HAVE_MALLOC_USABLE_SIZE || FF_HAVE_MSVC_MSIZE
78
#if __has_include(<malloc.h>)
@@ -13,6 +14,7 @@
1314
#include <malloc/malloc.h>
1415
#endif
1516

17+
FF_A_ALWAYS_INLINE FF_A_NONNULL(1)
1618
static inline void ffWrapFree(const void* pPtr) {
1719
assert(pPtr);
1820
if (*(void**) pPtr) {

src/common/strutil.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string.h>
66
#include <ctype.h>
77

8+
#include "common/attributes.h"
89
#include "common/wcwidth.h"
910

1011
#ifdef _WIN32
@@ -25,14 +26,17 @@ static inline bool ffStrSet(const char* str) {
2526
return *str != '\0';
2627
}
2728

29+
FF_A_ALWAYS_INLINE
2830
static inline bool ffStrStartsWithIgnCase(const char* str, const char* compareTo) {
2931
return strncasecmp(str, compareTo, strlen(compareTo)) == 0;
3032
}
3133

34+
FF_A_ALWAYS_INLINE
3235
static inline bool ffStrEqualsIgnCase(const char* str, const char* compareTo) {
3336
return strcasecmp(str, compareTo) == 0;
3437
}
3538

39+
FF_A_ALWAYS_INLINE
3640
static inline bool ffStrStartsWith(const char* str, const char* compareTo) {
3741
return strncmp(str, compareTo, strlen(compareTo)) == 0;
3842
}
@@ -55,26 +59,32 @@ static inline bool ffStrEndsWithIgnCase(const char* str, const char* compareTo)
5559
return strncasecmp(str + strLength - compareToLength, compareTo, compareToLength) == 0;
5660
}
5761

62+
FF_A_ALWAYS_INLINE
5863
static inline bool ffStrEquals(const char* str, const char* compareTo) {
5964
return strcmp(str, compareTo) == 0;
6065
}
6166

67+
FF_A_ALWAYS_INLINE
6268
static inline bool ffStrContains(const char* str, const char* compareTo) {
6369
return strstr(str, compareTo) != NULL;
6470
}
6571

72+
FF_A_ALWAYS_INLINE
6673
static inline bool ffStrContainsIgnCase(const char* str, const char* compareTo) {
6774
return strcasestr(str, compareTo) != NULL;
6875
}
6976

77+
FF_A_ALWAYS_INLINE
7078
static inline bool ffStrContainsC(const char* str, char compareTo) {
7179
return strchr(str, compareTo) != NULL;
7280
}
7381

82+
FF_A_ALWAYS_INLINE
7483
static inline bool ffCharIsEnglishAlphabet(char c) {
7584
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
7685
}
7786

87+
FF_A_ALWAYS_INLINE
7888
static inline bool ffCharIsDigit(char c) {
7989
return '0' <= c && c <= '9';
8090
}
@@ -86,6 +96,7 @@ uint8_t ffUtf8CharLenWidth(const char* str, uint32_t length, uint8_t* width);
8696

8797
uint32_t ffUtf8StrWidth(const char* str, uint32_t length);
8898

99+
FF_A_ALWAYS_INLINE
89100
static inline bool ffCharIsHexDigit(char c) {
90101
return ffCharIsDigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F');
91102
}

0 commit comments

Comments
 (0)