From: Alex Kost <alezost@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 1/2] emacs: main: Remove top-level package tables.
Date: Sun, 8 May 2016 13:51:01 +0300 [thread overview]
Message-ID: <1462704662-18972-2-git-send-email-alezost@gmail.com> (raw)
In-Reply-To: <1462704662-18972-1-git-send-email-alezost@gmail.com>
* emacs/guix-main.scm (%package-vhash, package-vhash, %package-table)
(package-table, name+version->key, key->name+version): Remove.
(package-by-address, packages-by-name+version): Adjust by using delayed
local package tables.
---
emacs/guix-main.scm | 73 ++++++++++++++++++-----------------------------------
1 file changed, 24 insertions(+), 49 deletions(-)
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index 2be86f0..5d7df2a 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -32,14 +32,6 @@
;; still "name-version" string. So ‘id’ package parameter in the code
;; below is either an object-address number or a full-name string.
-;; To speed-up the process of getting information, the following
-;; auxiliary variables are used:
-;;
-;; - `%packages' - VHash of "package address"/"package" pairs.
-;;
-;; - `%package-table' - Hash table of
-;; "name+version key"/"list of packages" pairs.
-
;;; Code:
(use-modules
@@ -101,38 +93,6 @@ return two values: name and version. For example, for SPEC
(string-append full-name ":" output)
full-name)))
-(define name+version->key cons)
-(define key->name+version car+cdr)
-
-(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
- (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
(manifest-entry-name entry)
@@ -340,15 +300,30 @@ Example:
\f
;;; Finding packages.
-(define (package-by-address address)
- (match (vhash-assq address (package-vhash))
- ((_ . package) package)
- (_ #f)))
-
-(define (packages-by-name+version name version)
- (or (hash-ref (package-table)
- (name+version->key name version))
- '()))
+(define package-by-address
+ (let ((table (delay (fold-packages
+ (lambda (package table)
+ (vhash-consq (object-address package)
+ package table))
+ vlist-null))))
+ (lambda (address)
+ "Return package by its object ADDRESS."
+ (match (vhash-assq address (force table))
+ ((_ . package) package)
+ (_ #f)))))
+
+(define packages-by-name+version
+ (let ((table (delay (fold-packages
+ (lambda (package table)
+ (let ((file (location-file
+ (package-location package))))
+ (vhash-cons (cons (package-name package)
+ (package-version package))
+ package table)))
+ vlist-null))))
+ (lambda (name version)
+ "Return packages matching NAME and VERSION."
+ (vhash-fold* cons '() (cons name version) (force table)))))
(define (packages-by-full-name full-name)
(call-with-values
--
2.7.3
next prev parent reply other threads:[~2016-05-08 10:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-08 10:51 [PATCH 0/2] emacs: Add "M-x guix-package-from-file Alex Kost
2016-05-08 10:51 ` Alex Kost [this message]
2016-05-08 16:54 ` [PATCH 1/2] emacs: main: Remove top-level package tables Ludovic Courtès
2016-05-08 10:51 ` [PATCH 2/2] emacs: Add 'guix-package-from-file' command Alex Kost
2016-05-08 18:40 ` Ludovic Courtès
2016-05-09 8:25 ` Alex Kost
2016-05-09 20:29 ` Ludovic Courtès
2016-05-10 9:09 ` Alex Kost
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=1462704662-18972-2-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.