Optimize `store-path?'.
* guix/store.scm (store-path?): Check with `string-prefix?' instead of a regexp.
This commit is contained in:
parent
d118c548b5
commit
f39bd08ad2
@ -414,13 +414,12 @@ Return #t on success."
|
|||||||
;; Absolute path to the Nix store.
|
;; Absolute path to the Nix store.
|
||||||
(make-parameter "/nix/store"))
|
(make-parameter "/nix/store"))
|
||||||
|
|
||||||
(define store-path?
|
(define (store-path? path)
|
||||||
(let ((store-path-rx
|
"Return #t if PATH is a store path."
|
||||||
(delay (make-regexp
|
;; This is a lightweight check, compared to using a regexp, but this has to
|
||||||
(string-append "^.*" (%store-prefix) "/[^-]{32}-(.+)$")))))
|
;; be fast as it's called often in `derivation', for instance.
|
||||||
(lambda (path)
|
;; `isStorePath' in Nix does something similar.
|
||||||
"Return #t if PATH is a store path."
|
(string-prefix? (%store-prefix) path))
|
||||||
(not (not (regexp-exec (force store-path-rx) path))))))
|
|
||||||
|
|
||||||
(define (derivation-path? path)
|
(define (derivation-path? path)
|
||||||
"Return #t if PATH is a derivation path."
|
"Return #t if PATH is a derivation path."
|
||||||
|
Loading…
Reference in New Issue
Block a user