speedup snow search

This commit is contained in:
Alex Shinn 2020-07-29 11:01:56 +09:00
parent a3d0d7a49c
commit 67dcd04d03

View file

@ -1046,13 +1046,18 @@
(map car lib-names+pkgs) (map car lib-names+pkgs)
(map cdr lib-names+pkgs))) (map cdr lib-names+pkgs)))
;; faster than (length (regexp-extract re str)) (define (string-count-word str word)
(define (regexp-count re str) (let lp ((sc (string-cursor-start str)) (count 0))
(regexp-fold re (lambda (from md str acc) (+ acc 1)) 0 str)) (let ((sc2 (string-contains str word sc)))
(if sc2
(lp (string-cursor-next str sc2) (+ count 1))
count))))
(define (count-in-sexp x keywords) (define (count-in-sexp x keywords)
(regexp-count `(word (w/nocase (or ,@keywords))) (let ((s (string-downcase (write-to-string x))))
(write-to-string x))) (fold (lambda (k sum) (+ sum (string-count-word s k)))
0
(map string-downcase keywords))))
(define (extract-matching-libraries cfg repo keywords) (define (extract-matching-libraries cfg repo keywords)
(define (library-score lib) (define (library-score lib)