X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=blobdiff_plain;f=src%2Fcoloredstderr.c;h=008da266bee76fbbc51efc7280edfe5dcf41fa47;hp=ccefdf34a31c9da821a58e868008a303e5310c14;hb=c2097785e752fee94c5c9ef46f03b8312694251a;hpb=5c8b5233fbadc8963cef28d851599bf4c34d271a diff --git a/src/coloredstderr.c b/src/coloredstderr.c index ccefdf3..008da26 100644 --- a/src/coloredstderr.c +++ b/src/coloredstderr.c @@ -66,7 +66,10 @@ static int check_handle_fd(int fd) { if (!initialized) { init_from_environment(); } - if (tracked_fds_list_count == 0) { + + /* tracked_fds_find() is most likely faster than calling isatty(), + * therefore check if we are tracking this file descriptor first. */ + if (!tracked_fds_find(fd)) { return 0; } @@ -76,7 +79,7 @@ static int check_handle_fd(int fd) { return 0; } - return tracked_fds_find(fd); + return 1; } static void dup_fd(int oldfd, int newfd) { @@ -87,9 +90,6 @@ static void dup_fd(int oldfd, int newfd) { if (!initialized) { init_from_environment(); } - if (tracked_fds_list_count == 0) { - return; - } /* We are already tracking this file descriptor, add newfd to the list as * it will reference the same descriptor. */ @@ -112,9 +112,6 @@ static void close_fd(int fd) { if (!initialized) { init_from_environment(); } - if (tracked_fds_list_count == 0) { - return; - } tracked_fds_remove(fd); }