aboutsummaryrefslogtreecommitdiff
path: root/emacs/guix-main.scm
diff options
context:
space:
mode:
authorAlex Kost <alezost@gmail.com>2016-03-31 22:13:23 +0300
committerAlex Kost <alezost@gmail.com>2016-04-04 20:11:22 +0300
commit183f42f90f2517e5cf16ac49fc571a70799e7ec6 (patch)
tree6bbdf8a0db1ad2f680493616b0306af79e53ecff /emacs/guix-main.scm
parent619ff9066d92f061fe17ab31748fa53d4648a697 (diff)
downloadpatches-183f42f90f2517e5cf16ac49fc571a70799e7ec6.tar
patches-183f42f90f2517e5cf16ac49fc571a70799e7ec6.tar.gz
emacs: Speed up starting the REPL.
Delay initializing variables. * emacs/guix-main.scm: (%packages): Rename to... (%package-vhash): ... this. Delay setting the value. (package-vhash): New procedure (wrapper for '%package-vhash'). (%package-table): Delay setting the value. (package-table): New procedure (wrapper for '%package-table'). (package-by-address, packages-by-name+version): Use wrappers.
Diffstat (limited to 'emacs/guix-main.scm')
-rw-r--r--emacs/guix-main.scm46
1 files changed, 28 insertions, 18 deletions
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 925d2b2b40..c62044056f 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -103,24 +103,34 @@ return two values: name and version. For example, for SPEC
(define name+version->key cons)
(define key->name+version car+cdr)
-(define %packages
- (fold-packages (lambda (pkg res)
- (vhash-consq (object-address pkg) pkg res))
- vlist-null))
+(define %package-vhash
+ (delay
+ (fold-packages (lambda (pkg res)
+ (vhash-consq (object-address pkg) pkg res))
+ vlist-null)))
+
+(define (package-vhash)
+ "Return vhash of 'package ID (address)'/'package' pairs."
+ (force %package-vhash))
(define %package-table
- (let ((table (make-hash-table (vlist-length %packages))))
- (vlist-for-each
- (lambda (elem)
- (match elem
- ((address . pkg)
- (let* ((key (name+version->key (package-name pkg)
- (package-version pkg)))
- (ref (hash-ref table key)))
- (hash-set! table key
- (if ref (cons pkg ref) (list pkg)))))))
- %packages)
- table))
+ (delay
+ (let ((table (make-hash-table (vlist-length (package-vhash)))))
+ (vlist-for-each
+ (lambda (elem)
+ (match elem
+ ((address . pkg)
+ (let* ((key (name+version->key (package-name pkg)
+ (package-version pkg)))
+ (ref (hash-ref table key)))
+ (hash-set! table key
+ (if ref (cons pkg ref) (list pkg)))))))
+ (package-vhash))
+ table)))
+
+(define (package-table)
+ "Return hash table of 'name+version key'/'list of packages' pairs."
+ (force %package-table))
(define (manifest-entry->name+version+output entry)
(values
@@ -330,12 +340,12 @@ Example:
;;; Finding packages.
(define (package-by-address address)
- (match (vhash-assq address %packages)
+ (match (vhash-assq address (package-vhash))
((_ . package) package)
(_ #f)))
(define (packages-by-name+version name version)
- (or (hash-ref %package-table
+ (or (hash-ref (package-table)
(name+version->key name version))
'()))