utils: Micro-optimize 'bytevector->base16-string'.

This reduces run time of (package-derivation s emacs) by ~1.5%.

* guix/utils.scm (bytevector->base16-string): Traverse BV from the end
  so as to use 'string-concatenate' instead of
  'string-concatenate-reverse'.
This commit is contained in:
Ludovic Courtès 2014-10-13 23:07:47 +02:00
parent 8601d0ddcf
commit 998fb8fa1d
1 changed files with 6 additions and 5 deletions

View File

@ -121,12 +121,13 @@ evaluate to a simple datum."
0))))
v))))))
(define chars base16-chars)
(let loop ((i 0)
(let loop ((i len)
(r '()))
(if (= i len)
(string-concatenate-reverse r)
(loop (+ 1 i)
(cons (vector-ref chars (bytevector-u8-ref bv i)) r))))))
(if (zero? i)
(string-concatenate r)
(let ((i (- i 1)))
(loop i
(cons (vector-ref chars (bytevector-u8-ref bv i)) r)))))))
(define base16-string->bytevector
(let ((chars->value (fold (lambda (i r)