[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/08: gexp: Micro-optimize sexp serialization.

From: Ludovic Courtès
Subject: 03/08: gexp: Micro-optimize sexp serialization.
Date: Fri, 13 May 2016 21:49:50 +0000 (UTC)

civodul pushed a commit to branch wip-build-systems-gexp
in repository guix.

commit d3c3ffb8fc69e747552fa878bc1666780431c40a
Author: Ludovic Courtès <address@hidden>
Date:   Sat Mar 28 21:44:01 2015 +0100

    gexp: Micro-optimize sexp serialization.
    * guix/gexp.scm (sexp->string): New procedure.
      (gexp->derivation): Use it instead of 'object->string'.
 guix/gexp.scm |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index bc2df4b..520bb26 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -455,6 +455,15 @@ names and file names suitable for the #:allowed-references 
argument to
     (lambda (system)
       ((force proc) system))))
+(define (sexp->string sexp)
+  "Like 'object->string', but deterministic and slightly faster."
+  ;; Explicitly use UTF-8 for determinism, and also because UTF-8 output is
+  ;; faster.
+  (with-fluids ((%default-port-encoding "UTF-8"))
+    (call-with-output-string
+     (lambda (port)
+       (write sexp port)))))
 (define* (gexp->derivation name exp
                            system (target 'current)
@@ -538,7 +547,7 @@ The other arguments are as for 'derivation'."
                                              #:system system
                                              #:target target))
                        (builder  (text-file script-name
-                                            (object->string sexp)))
+                                            (sexp->string sexp)))
                        (modules  (if (pair? %modules)
                                      (imported-modules %modules
                                                        #:system system

reply via email to

[Prev in Thread] Current Thread [Next in Thread]