summaryrefslogtreecommitdiff
path: root/guix/store.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-01-30 00:37:26 +0100
committerLudovic Courtès <ludo@gnu.org>2013-01-30 00:37:26 +0100
commit82c38fe64c84fc3febcc5c5aa7fe86454ccaf456 (patch)
treea24f8d13a4a9043789eb2f0c6898e4d87aa652a2 /guix/store.scm
parent473b03b3c6fbca909e18dbb5888ac5a98992207a (diff)
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".
Diffstat (limited to 'guix/store.scm')
-rw-r--r--guix/store.scm11
1 files changed, 7 insertions, 4 deletions
diff --git a/guix/store.scm b/guix/store.scm
index f36ebea390..b0531b9915 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -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))