summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-06-25 07:55:59 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-06-25 07:55:59 -0700
commitb30ef1a6cb0892c142cd8ccad671e1ad2dae903a (patch)
tree3cf251a135e23efa9f1dd76decff7e988f2b230b /lib.c
parent589349fdb3eb0421a0fc0622cc198bd55ca7cc04 (diff)
downloadtxr-b30ef1a6cb0892c142cd8ccad671e1ad2dae903a.tar.gz
txr-b30ef1a6cb0892c142cd8ccad671e1ad2dae903a.tar.bz2
txr-b30ef1a6cb0892c142cd8ccad671e1ad2dae903a.zip
in: use seq_info
* lib.c (in): Keep the existing specialized cases, but use seq_info in the fallback.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/lib.c b/lib.c
index e98c7614..1d76aa65 100644
--- a/lib.c
+++ b/lib.c
@@ -9665,33 +9665,11 @@ val drop_until(val pred, val seq, val keyfun)
val in(val seq, val item, val testfun, val keyfun)
{
val self = lit("in");
- switch (type(seq)) {
+ seq_info_t si = seq_info(seq);
+
+ switch (si.type) {
case NIL:
return nil;
- case COBJ:
- if (seq->co.cls == hash_s)
- return tnil(gethash_e(self, seq, item));
- /* fallthrough */
- case CONS:
- case LCONS:
- {
- testfun = default_arg(testfun, equal_f);
- keyfun = default_arg(keyfun, identity_f);
-
- seq = nullify(seq);
-
- gc_hint(seq);
-
- for (; seq; seq = cdr(seq)) {
- val elem = car(seq);
- val key = funcall1(keyfun, elem);
-
- if (funcall2(testfun, item, key))
- return t;
- }
-
- return nil;
- }
case LIT:
case STR:
case LSTR:
@@ -9729,7 +9707,31 @@ val in(val seq, val item, val testfun, val keyfun)
return nil;
}
default:
- type_mismatch(lit("in: ~s is not a sequence or hash"), seq, nao);
+ switch (si.kind) {
+ case SEQ_HASHLIKE:
+ return tnil(gethash_e(self, si.obj, item));
+ case SEQ_LISTLIKE:
+ case SEQ_VECLIKE:
+ {
+ seq_iter_t iter;
+ val elem;
+
+ seq_iter_init(self, &iter, seq);
+
+ testfun = default_arg(testfun, equal_f);
+ keyfun = default_arg(keyfun, identity_f);
+
+ while (seq_get(&iter, &elem)) {
+ val key = funcall1(keyfun, elem);
+ if (funcall2(testfun, item, key))
+ return t;
+ }
+
+ return nil;
+ }
+ default:
+ type_mismatch(lit("in: ~s is not a sequence"), seq, nao);
+ }
}
}