all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alex Kost <alezost@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 4/4] emacs: Speed up starting the REPL.
Date: Fri,  1 Apr 2016 11:06:42 +0300	[thread overview]
Message-ID: <1459498002-3872-5-git-send-email-alezost@gmail.com> (raw)
In-Reply-To: <1459498002-3872-1-git-send-email-alezost@gmail.com>

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.
---
 emacs/guix-main.scm | 46 ++++++++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 925d2b2..c620440 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))
       '()))
 
-- 
2.7.3

  parent reply	other threads:[~2016-04-01  8:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-01  8:06 [PATCH 0/4] emacs: Some fixes and improvements Alex Kost
2016-04-01  8:06 ` [PATCH 1/4] emacs: Stylistic improvements in guile code Alex Kost
2016-04-03 21:16   ` Ludovic Courtès
2016-04-01  8:06 ` [PATCH 2/4] emacs: Remove unused module Alex Kost
2016-04-03 21:16   ` Ludovic Courtès
2016-04-01  8:06 ` [PATCH 3/4] emacs: Use (guix scripts lint) only when needed Alex Kost
2016-04-03 21:18   ` Ludovic Courtès
2016-04-01  8:06 ` Alex Kost [this message]
2016-04-03 21:19   ` [PATCH 4/4] emacs: Speed up starting the REPL Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459498002-3872-5-git-send-email-alezost@gmail.com \
    --to=alezost@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.