gexp: Micro-optimize sexp serialization.

* guix/gexp.scm (sexp->string): New procedure.
(gexp->derivation): Use it instead of 'object->string'.
This commit is contained in:
Ludovic Courtès 2015-03-28 21:44:01 +01:00
parent 70b33d8898
commit bde7929bd0
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
;;; Copyright © 2018 Jan Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2019, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
@ -941,6 +941,15 @@ (define* (imported+compiled-modules modules system
modules
system extensions guile deprecation-warnings module-path))
(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* (lower-gexp exp
#:key
(module-path %load-path)
@ -1159,7 +1168,7 @@ (define (add-modules exp modules)
(return #f)))
(guile -> (lowered-gexp-guile lowered))
(builder (text-file script-name
(object->string
(sexp->string
(lowered-gexp-sexp lowered)))))
(mbegin %store-monad
(set-grafting graft?) ;restore the initial setting