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:
Simon Ruderich
2013-06-07 01:27:58 +02:00
parent 5c8b5233fb
commit c2097785e7
5 changed files with 134 additions and 42 deletions

View File

@@ -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);
}