store: Micro-optimize `write-string'.

* guix/store.scm (write-string): Optimize to write the length, contents,
  and padding all at once.  This yields a 2% improvement on the
  execution time of "guix-build gdb".
This commit is contained in:
Ludovic Courtès 2013-01-30 00:37:26 +01:00
parent 473b03b3c6
commit 82c38fe64c
1 changed files with 7 additions and 4 deletions

View File

@ -158,10 +158,13 @@
(put-bytevector p zero 0 (- 8 m)))))))
(define (write-string s p)
(let ((b (string->utf8 s)))
(write-int (bytevector-length b) p)
(put-bytevector p b)
(write-padding (bytevector-length b) p)))
(let* ((s (string->utf8 s))
(l (bytevector-length s))
(m (modulo l 8))
(b (make-bytevector (+ 8 l (if (zero? m) 0 (- 8 m))))))
(bytevector-u64-native-set! b 0 l)
(bytevector-copy! s 0 b 8 l)
(put-bytevector p b)))
(define (read-string p)
(let* ((len (read-int p))