mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-12 01:48:33 +01:00
Use static list of descriptors to reduce mallocs.
Only if file descriptors with a value > 255 occur, the list implementation is used.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user