When enlarging a large_fd_set, use FD_ZERO if possible
The most common case of creating a large_fd_set on UNIX
is to create it with size zero, and then immediately enlarge
it to size FD_SETSIZE. Instead of looping and calling
FD_CLR(), we can optimize this common case with the OS's
FD_ZERO.
diff --git a/snmplib/large_fd_set.c b/snmplib/large_fd_set.c
index 32f57b3..2967d3c 100644
--- a/snmplib/large_fd_set.c
+++ b/snmplib/large_fd_set.c
@@ -174,13 +174,16 @@
}
#if defined(cygwin) || !defined(HAVE_WINSOCK_H)
- {
+ /*
+ * Unix: when enlarging, clear the file descriptors defined in the
+ * resized *fdset but that were not defined in the original *fdset.
+ */
+ if ( fdset->lfs_setsize == 0 && setsize == FD_SETSIZE ) {
+ /* In this case we can use the OS's FD_ZERO */
+ FD_ZERO( fdset->lfs_setptr );
+ } else {
int i;
- /*
- * Unix: when enlarging, clear the file descriptors defined in the
- * resized *fdset but that were not defined in the original *fdset.
- */
for (i = fdset->lfs_setsize; i < setsize; i++)
FD_CLR(i, fdset->lfs_setptr);
}