aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-09-01 19:21:06 +0200
committerLudovic Courtès <ludo@gnu.org>2012-09-01 23:38:28 +0200
commitf39bd08ad223ae831312c9896e18f2f05ca5cbd0 (patch)
tree0c95ae9c4f7560fdfa87e9c04e67c2cd1842a7c1
parentd118c548b5779fe136da03bd732bef2294618b97 (diff)
downloadgnu-guix-f39bd08ad223ae831312c9896e18f2f05ca5cbd0.tar
gnu-guix-f39bd08ad223ae831312c9896e18f2f05ca5cbd0.tar.gz
Optimize `store-path?'.
* guix/store.scm (store-path?): Check with `string-prefix?' instead of a regexp.
-rw-r--r--guix/store.scm13
1 files changed, 6 insertions, 7 deletions
diff --git a/guix/store.scm b/guix/store.scm
index 1e6119ed18..3eedcbed57 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -414,13 +414,12 @@ Return #t on success."
;; Absolute path to the Nix store.
(make-parameter "/nix/store"))
-(define store-path?
- (let ((store-path-rx
- (delay (make-regexp
- (string-append "^.*" (%store-prefix) "/[^-]{32}-(.+)$")))))
- (lambda (path)
- "Return #t if PATH is a store path."
- (not (not (regexp-exec (force store-path-rx) path))))))
+(define (store-path? path)
+ "Return #t if PATH is a store path."
+ ;; This is a lightweight check, compared to using a regexp, but this has to
+ ;; be fast as it's called often in `derivation', for instance.
+ ;; `isStorePath' in Nix does something similar.
+ (string-prefix? (%store-prefix) path))
(define (derivation-path? path)
"Return #t if PATH is a derivation path."