Commit 4fe23efc authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

input: avoid heap-allocation in vlc_poll_i11e() in most cases

parent 2bd02c89
...@@ -328,14 +328,23 @@ int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout) ...@@ -328,14 +328,23 @@ int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout)
int ret; int ret;
struct pollfd *ufd = malloc((nfds + 1) * sizeof (*ufd)); if (likely(nfds < 255))
if (unlikely(ufd == NULL)) { /* Fast path with stack allocation */
return -1; /* ENOMEM */ struct pollfd ufd[nfds + 1];
vlc_cleanup_push(free, ufd); ret = vlc_poll_i11e_inner(fds, nfds, timeout, ctx, ufd);
ret = vlc_poll_i11e_inner(fds, nfds, timeout, ctx, ufd); }
vlc_cleanup_pop(); else
free(ufd); { /* Slow path but poll() is slow with large nfds anyway. */
struct pollfd *ufd = malloc((nfds + 1) * sizeof (*ufd));
if (unlikely(ufd == NULL))
return -1; /* ENOMEM */
vlc_cleanup_push(free, ufd);
ret = vlc_poll_i11e_inner(fds, nfds, timeout, ctx, ufd);
vlc_cleanup_pop();
free(ufd);
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment