NO-JIRA: Avoid needless realloc() calls in driver_rebuild
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/bec25232 Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/bec25232 Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/bec25232 Branch: refs/heads/master Commit: bec252326634e4fb08f531b1cda00447a94bfcaf Parents: 365f851 Author: Alan Conway <[email protected]> Authored: Tue Nov 22 11:31:53 2016 -0500 Committer: Alan Conway <[email protected]> Committed: Fri Nov 25 11:57:40 2016 -0500 ---------------------------------------------------------------------- src/posix/driver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/bec25232/src/posix/driver.c ---------------------------------------------------------------------- diff --git a/src/posix/driver.c b/src/posix/driver.c index 8d82127..d7c7eea 100644 --- a/src/posix/driver.c +++ b/src/posix/driver.c @@ -903,11 +903,15 @@ static void qdpn_driver_rebuild(qdpn_driver_t *d) { sys_mutex_lock(d->lock); size_t size = DEQ_SIZE(d->listeners) + DEQ_SIZE(d->connectors); - while (d->capacity < size + 1) { - d->capacity = d->capacity ? 2*d->capacity : 16; + if (d->capacity < size + 1) { + d->capacity = d->capacity > 16 ? d->capacity : 16; + while (d->capacity < size + 1) { + d->capacity *= 2; + } d->fds = (struct pollfd *) realloc(d->fds, d->capacity*sizeof(struct pollfd)); } + d->wakeup = 0; d->nfds = 0; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
