[Optimize make-index-mapper and get-instances-limit clinton@unknownlamer.org**20080115221508 * Now supports skipping natively and does not cons extra cells * Takes a result-fn that is passed the result instead of accumulating a list if it is provided * Use result-fn in get-instances-limit to fetch instances into local list and return that rather than collect in map-inverted-index for the fewer results than limit case * Now only needed conses are allocated ] { hunk ./src/database.lisp 9 -(defun make-index-mapper (fn limit) +(defun make-index-mapper (fn limit &optional (skip 0) result-fn) hunk ./src/database.lisp 11 - (results '())) + (limit (or limit -1)) ; nil -> no limit + (results (list))) hunk ./src/database.lisp 17 + ((< curr skip) (decf skip) nil) hunk ./src/database.lisp 19 - (car (push (apply fn args) results))))))) + (let ((result (apply fn args))) + (car + (if result-fn + (funcall result-fn result) + (push result results))))))))) hunk ./src/database.lisp 35 - (let ((mapper (if limit - (make-index-mapper #'elephant::identity2 - (+ limit skip)) - #'elephant::identity2))) - (nthcdr - skip - (handler-case - (map-inverted-index mapper - class - slot-name - :start start :end end - :collect t :from-end from-end) - (results-limit-reached (c) (values (limit-result c) (limit-count c))))))) + (let ((results (list))) + (labels ((result-pusher (result) (push result results))) + (nreverse + (handler-case + (progn + (map-inverted-index (make-index-mapper #'elephant::identity2 + limit skip #'result-pusher) + class + slot-name + :start start :end end + :collect nil :from-end from-end) + results) + (results-limit-reached () results)))))) }