mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-09 16:38:32 +01:00
Inline fast part of tracked_fds_find().
This commit is contained in:
@@ -43,6 +43,7 @@ AC_TYPE_SIZE_T
|
||||
AC_TYPE_SSIZE_T
|
||||
|
||||
AC_C_INLINE
|
||||
AX_C___ATTRIBUTE__
|
||||
|
||||
AC_FUNC_FORK
|
||||
AC_CHECK_FUNCS([dup2 memmove setenv strdup])
|
||||
|
||||
@@ -20,6 +20,17 @@
|
||||
#ifndef COMPILER_H
|
||||
#define COMPILER_H 1
|
||||
|
||||
/* Prevent/force inlining. Used to improve performance. */
|
||||
#undef __noinline
|
||||
#undef __always_inline
|
||||
#ifdef HAVE___ATTRIBUTE__
|
||||
# define __noinline __attribute__((noinline))
|
||||
# define __always_inline __attribute__((always_inline))
|
||||
#else
|
||||
# define __noinline
|
||||
# define __always_inline
|
||||
#endif
|
||||
|
||||
/* Branch prediction information for the compiler. */
|
||||
#ifdef HAVE___BUILTIN_EXPECT
|
||||
# define likely(x) __builtin_expect(!!(x), 1)
|
||||
|
||||
@@ -299,10 +299,25 @@ static int tracked_fds_remove(int fd) {
|
||||
/* Not found. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tracked_fds_find_slow(int fd);
|
||||
/*
|
||||
* tracked_fds_find() is called for each hook call and should be as fast as
|
||||
* possible. As most file descriptors are < TRACKFDS_STATIC_COUNT, force the
|
||||
* compiler to inline that part which is almost exclusively used.
|
||||
*
|
||||
* Inlining tracked_fds_add()/tracked_fds_remove() isn't worth the effort as
|
||||
* they are not called often enough.
|
||||
*/
|
||||
inline static int tracked_fds_find(int fd) __always_inline;
|
||||
static int tracked_fds_find(int fd) {
|
||||
if (fd < TRACKFDS_STATIC_COUNT) {
|
||||
return tracked_fds[fd];
|
||||
}
|
||||
|
||||
return tracked_fds_find_slow(fd);
|
||||
}
|
||||
static int tracked_fds_find_slow(int fd) {
|
||||
if (tracked_fds_list_count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user