summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-02-29 20:36:25 -0800
committerKaz Kylheku <kaz@kylheku.com>2024-02-29 20:36:25 -0800
commit9cfa3435672667fe0fe9abc59b9e1352c4a276d3 (patch)
tree195865754e78b9f34d06f8d8d6bd4edefd354df7 /lib.c
parente8dedb798f4333e5fc2c85e37c019600010b6f7d (diff)
downloadtxr-9cfa3435672667fe0fe9abc59b9e1352c4a276d3.tar.gz
txr-9cfa3435672667fe0fe9abc59b9e1352c4a276d3.tar.bz2
txr-9cfa3435672667fe0fe9abc59b9e1352c4a276d3.zip
partition, split, split*: iter used for indices
* lib.c (partition_func, split_func, split_star_func): Indices passed through lazy cons are now iterator, rather than a sequence accessed via car and cdr, which is inefficient for nonlists. (partition-split-common): Use iter-begin to convert indices to iterator, which becomes the cdr field of the lazy cons. * txr.1: Update documentation for these functions to clarify that the second argument is a sequence. The inaccurate text claiming that "if the second argument is an atom other than a function" is rewritten. This doesn't describe the behavior that is implemented, where the test applied is seqp, not atom. The indices can be a vector of integers, which is an atom.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib.c b/lib.c
index 94156bd3..52326b2d 100644
--- a/lib.c
+++ b/lib.c
@@ -4003,8 +4003,8 @@ static val partition_func(val base, val lcons)
val len = nil;
for (;;) {
- if (indices) {
- val raw_index = pop(&indices);
+ if (iter_more(indices)) {
+ val raw_index = iter_item(indices);
val index = if3((!opt_compat || opt_compat > 170) && minusp(raw_index),
plus(raw_index, if3(len, len, len = length(seq))),
raw_index);
@@ -4019,7 +4019,8 @@ static val partition_func(val base, val lcons)
if (rest) {
val fun = us_lcons_fun(lcons);
us_func_set_env(fun, index);
- us_rplacd(lcons, make_lazy_cons_car_cdr(fun, rest, indices));
+ us_rplacd(lcons, make_lazy_cons_car_cdr(fun, rest,
+ iter_step(indices)));
} else {
us_rplacd(lcons, nil);
}
@@ -4042,8 +4043,8 @@ static val split_func(val base, val lcons)
val len = nil;
for (;;) {
- if (indices) {
- val raw_index = pop(&indices);
+ if (iter_more(indices)) {
+ val raw_index = iter_item(indices);
val index = if3((!opt_compat || opt_compat > 170) && minusp(raw_index),
plus(raw_index, if3(len, len, len = length(seq))),
raw_index);
@@ -4059,7 +4060,8 @@ static val split_func(val base, val lcons)
if (rest) {
val fun = us_lcons_fun(lcons);
us_func_set_env(fun, index);
- us_rplacd(lcons, make_lazy_cons_car_cdr(fun, rest, indices));
+ us_rplacd(lcons, make_lazy_cons_car_cdr(fun, rest,
+ iter_step(indices)));
} else {
us_rplacd(lcons, cons(rsub, nil));
}
@@ -4082,8 +4084,8 @@ static val split_star_func(val base, val lcons)
val len = nil;
for (;;) {
- if (indices) {
- val raw_index = pop(&indices);
+ if (iter_more(indices)) {
+ val raw_index = iter_item(indices);
val index = if3((!opt_compat || opt_compat > 170) && minusp(raw_index),
plus(raw_index, if3(len, len, len = length(seq))),
raw_index);
@@ -4099,7 +4101,8 @@ static val split_star_func(val base, val lcons)
if (rest) {
val fun = us_lcons_fun(lcons);
us_func_set_env(fun, succ(index));
- us_rplacd(lcons, make_lazy_cons_car_cdr(fun, rest, indices));
+ us_rplacd(lcons, make_lazy_cons_car_cdr(fun, rest,
+ iter_step(indices)));
} else {
us_rplacd(lcons, cons(rsub, nil));
}
@@ -4135,7 +4138,8 @@ static val partition_split_common(val seq, val indices,
if (!seqp(indices))
indices = cons(indices, nil);
- return make_lazy_cons_car_cdr(func_f1(zero, split_fptr), seq, indices);
+ return make_lazy_cons_car_cdr(func_f1(zero, split_fptr), seq,
+ iter_begin(indices));
}
val partition(val seq, val indices)