[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
04/12: memoization: Micro-optimize code produced by 'define-cache-proced
From: |
Ludovic Courtès |
Subject: |
04/12: memoization: Micro-optimize code produced by 'define-cache-procedure'. |
Date: |
Thu, 16 Mar 2017 18:04:23 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 146db52a188b871769d9512867aa7f409f37dbac
Author: Ludovic Courtès <address@hidden>
Date: Thu Mar 16 13:41:51 2017 +0100
memoization: Micro-optimize code produced by 'define-cache-procedure'.
* guix/memoization.scm (%nothing): Remove.
(define-cache-procedure): Make '%nothing' a local variable, with a
literal list.
---
guix/memoization.scm | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/guix/memoization.scm b/guix/memoization.scm
index d64f60f..5cae283 100644
--- a/guix/memoization.scm
+++ b/guix/memoization.scm
@@ -31,9 +31,6 @@
(define-syntax-rule (return/1 value)
value)
-(define %nothing ;nothingness
- (list 'this 'is 'nothing))
-
(define-syntax define-cache-procedure
(syntax-rules ()
"Define a procedure NAME that implements a cache using HASH-REF and
@@ -41,15 +38,17 @@ HASH-SET!. Use CALL to invoke the thunk and RETURN to
return its value; CALL
and RETURN are used to distinguish between multiple-value and single-value
returns."
((_ name hash-ref hash-set! call return)
- (define (name cache key thunk)
- "Cache the result of THUNK under KEY in CACHE, or return the
+ (define name
+ (let ((%nothing '(this is nothing)))
+ (lambda (cache key thunk)
+ "Cache the result of THUNK under KEY in CACHE, or return the
already-cached result."
- (let ((results (hash-ref cache key %nothing)))
- (if (eq? results %nothing)
- (let ((results (call thunk)))
- (hash-set! cache key results)
- (return results))
- (return results)))))
+ (let ((results (hash-ref cache key %nothing)))
+ (if (eq? results %nothing)
+ (let ((results (call thunk)))
+ (hash-set! cache key results)
+ (return results))
+ (return results)))))))
((_ name hash-ref hash-set!)
(define-cache-procedure name hash-ref hash-set!
call/mv return/mv))))
- branch master updated (2c715a9 -> ad172c4), Ludovic Courtès, 2017/03/16
- 05/12: pack: Honor command-line options related to the store., Ludovic Courtès, 2017/03/16
- 02/12: gexp: Add '=>' syntax to import computed modules., Ludovic Courtès, 2017/03/16
- 03/12: services: connman: Rework service., Ludovic Courtès, 2017/03/16
- 04/12: memoization: Micro-optimize code produced by 'define-cache-procedure'.,
Ludovic Courtès <=
- 07/12: pack: Use a fixed timestamp in Docker images., Ludovic Courtès, 2017/03/16
- 01/12: utils: Move base16 procedures to (guix base16)., Ludovic Courtès, 2017/03/16
- 09/12: pack: Honor symlinks in the Docker back-end., Ludovic Courtès, 2017/03/16
- 11/12: doc: Mention 'guix pack' reproducibility., Ludovic Courtès, 2017/03/16
- 10/12: pack: Allow for "-S /opt/foo="., Ludovic Courtès, 2017/03/16
- 12/12: doc: Reorganize categories., Ludovic Courtès, 2017/03/16
- 06/12: pack: Add '--format' option and Docker output support., Ludovic Courtès, 2017/03/16
- 08/12: docker: Build images in a reproducible fashion., Ludovic Courtès, 2017/03/16