Faster version of _list-index

This commit is contained in:
Justin Ethier 2019-03-14 15:43:36 -04:00
parent a72e91b85c
commit 1f7212a964

View file

@ -1864,16 +1864,12 @@
(lambda (obj val)
(vector-set! (vector-ref obj 2) idx val)))
;; Find index of element in list, or -1 if not found
;; Find index of element in list, or #f if not found
(define _list-index
(lambda (e lst)
(if (null? lst)
-1
(if (eq? (car lst) e)
0
(if (= (_list-index e (cdr lst)) -1)
-1
(+ 1 (_list-index e (cdr lst))))))))
(lambda (e lst1)
(let lp ((lis lst1) (n 0))
(and (not (null? lis))
(if (eq? e (car lis)) n (lp (cdr lis) (+ n 1)))))))
(define (record? obj)
(and (vector? obj)