From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH 4/4] emacs: Speed up starting the REPL. Date: Fri, 1 Apr 2016 11:06:42 +0300 Message-ID: <1459498002-3872-5-git-send-email-alezost@gmail.com> References: <1459498002-3872-1-git-send-email-alezost@gmail.com> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alu6h-0007uO-RK for guix-devel@gnu.org; Fri, 01 Apr 2016 04:07:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alu6g-0000So-RS for guix-devel@gnu.org; Fri, 01 Apr 2016 04:07:03 -0400 Received: from mail-lb0-x244.google.com ([2a00:1450:4010:c04::244]:36571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alu6g-0000Si-Jj for guix-devel@gnu.org; Fri, 01 Apr 2016 04:07:02 -0400 Received: by mail-lb0-x244.google.com with SMTP id q4so8740926lbq.3 for ; Fri, 01 Apr 2016 01:07:02 -0700 (PDT) Received: from localhost.localdomain ([217.107.192.146]) by smtp.gmail.com with ESMTPSA id e66sm1974222lfg.23.2016.04.01.01.07.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Apr 2016 01:07:01 -0700 (PDT) In-Reply-To: <1459498002-3872-1-git-send-email-alezost@gmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org 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