summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-03-16 20:34:07 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-03-16 20:34:07 -0700
commit88d8fdbdd42b1960d548b05030282a79b5c6ad1f (patch)
treebb9e78f67631fb326d447cd001e3dd46f578f5d9
parent4ee59957790a0c3c5fa9555b946239540e76ea27 (diff)
downloadtxr-88d8fdbdd42b1960d548b05030282a79b5c6ad1f.tar.gz
txr-88d8fdbdd42b1960d548b05030282a79b5c6ad1f.tar.bz2
txr-88d8fdbdd42b1960d548b05030282a79b5c6ad1f.zip
poll: iterate sequences efficiently.
* sysif.c (poll_wrap): Use seq_iter for efficience when poll_list is a vector or other generalized sequence. * txr.1: Change wording to say that poll-list is a sequence.
-rw-r--r--sysif.c16
-rw-r--r--txr.12
2 files changed, 11 insertions, 7 deletions
diff --git a/sysif.c b/sysif.c
index edf3d185..85ff8a50 100644
--- a/sysif.c
+++ b/sysif.c
@@ -1452,13 +1452,16 @@ static val poll_wrap(val poll_list, val timeout_in)
{
val self = lit("poll");
nfds_t i, len = c_num(length(poll_list), self);
- val iter;
+ seq_iter_t iter;
+ val elem;
struct pollfd *pfd = coerce(struct pollfd *, alloca(len * sizeof *pfd));
val timeout = default_arg(timeout_in, negone);
int res;
- for (i = 0, iter = poll_list; iter; iter = cdr(iter), i++) {
- cons_bind (obj, events, car(iter));
+ seq_iter_init(self, &iter, poll_list);
+
+ for (i = 0; seq_get(&iter, &elem); i++) {
+ cons_bind (obj, events, elem);
pfd[i].events = c_num(events, self);
@@ -1504,10 +1507,11 @@ static val poll_wrap(val poll_list, val timeout_in)
{
list_collect_decl (out, ptail);
- for (i = 0, iter = poll_list; iter; iter = cdr(iter), i++) {
- val pair = car(iter);
+ seq_iter_init(self, &iter, poll_list);
+
+ for (i = 0; seq_get(&iter, &elem); i++) {
if (pfd[i].revents)
- ptail = list_collect(ptail, cons(car(pair), num(pfd[i].revents)));
+ ptail = list_collect(ptail, cons(car(elem), num(pfd[i].revents)));
}
return out;
diff --git a/txr.1 b/txr.1
index ce6ece74..4da6bf8e 100644
--- a/txr.1
+++ b/txr.1
@@ -64554,7 +64554,7 @@ for specified events. It is a wrapper for the same-named POSIX function.
The
.meta poll-list
-argument is a list of
+argument is a sequence of
.code cons
pairs. The
.code car