X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Ftrackfds.h;h=eddff4c5b5dc92bbf296c0e52b3979231479900c;hb=488159627f4f579a80b71c5f7713126864d5623f;hp=9b2aaa6701c854f6c3c7ae3c570b4984ebf1b289;hpb=dfd317650f05542db49d7bc37649a232f28efa3f;p=coloredstderr%2Fcoloredstderr.git diff --git a/src/trackfds.h b/src/trackfds.h index 9b2aaa6..eddff4c 100644 --- a/src/trackfds.h +++ b/src/trackfds.h @@ -299,10 +299,25 @@ static int tracked_fds_remove(int fd) { /* Not found. */ return 0; } + +static int tracked_fds_find_slow(int fd) __noinline; +/* + * 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; }