summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorArun Isaac <arunisaac@systemreboot.net>2020-06-01 04:48:01 +0530
committerArun Isaac <arunisaac@systemreboot.net>2020-06-15 23:31:56 +0530
commite70a88470622b513366076a0c435648daa56c084 (patch)
tree3cb6406758f796647ea73383f4f8ee07d0797d9a /guix
parentcf48f0fc4c40a2ec0b38a445e1e13f37722a0ade (diff)
downloadguix-patches-e70a88470622b513366076a0c435648daa56c084.tar
guix-patches-e70a88470622b513366076a0c435648daa56c084.tar.gz
ui: Cut off search early if any regexp does not match.
* guix/ui.scm (relevance): When one of the regexps does not match, cut off early and return 0. Do not try to match the remaining regexps.
Diffstat (limited to 'guix')
-rw-r--r--guix/ui.scm16
1 files changed, 11 insertions, 5 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index 7690f48660..c1c9b6e3ea 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -14,6 +14,7 @@
;;; Copyright © 2019 Chris Marusich <cmmarusich@gmail.com>
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2019 Simon Tournier <zimon.toutoune@gmail.com>
+;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -1520,11 +1521,16 @@ score, the more relevant OBJ is to REGEXPS."
(+ relevance (* weight (apply + (map score-regexp lst)))))))))
0 metrics)))
- (let ((scores (map regexp->score regexps)))
- ;; Return zero if one of REGEXPS doesn't match.
- (if (any zero? scores)
- 0
- (reduce + 0 scores))))
+ (let loop ((regexps regexps)
+ (total-score 0))
+ (match regexps
+ ((head . tail)
+ (let ((score (regexp->score head)))
+ ;; Return zero if one of PATTERNS doesn't match.
+ (if (zero? score)
+ 0
+ (loop tail (+ total-score score)))))
+ (() total-score))))
(define %package-metrics
;; Metrics used to compute the "relevance score" of a package against a set