(if (default-object? modulus)
((ucode-primitive string-hash) bytevector)
((ucode-primitive string-hash-mod) bytevector modulus)))
+
+(define (bytevector-builder)
+ (let ((builder
+ (make-sequence-builder (lambda () (allocate-bytevector 16))
+ bytevector-length
+ bytevector-u8-set!
+ bytevector-builder:finish-build)))
+ (lambda (#!optional object)
+ (cond ((default-object? object) ((builder 'build)))
+ ((byte? object) ((builder 'append-element!) object))
+ ((bytevector? object) ((builder 'append-sequence!) object))
+ ((memq object '(empty? count reset!)) ((builder object)))
+ (else (error "Not a byte or bytevector:" object))))))
+
+(define (bytevector-builder:finish-build parts)
+ (let ((result
+ (do ((parts parts (cdr parts))
+ (n 0 (fix:+ n (cdar parts))))
+ ((not (pair? parts))
+ (allocate-bytevector n)))))
+ (do ((parts parts (cdr parts))
+ (i 0 (fix:+ i (cdar parts))))
+ ((not (pair? parts)))
+ (bytevector-copy! result i (caar parts) 0 (cdar parts)))
+ result))
\f
;;;; U16 accessors
(legacy-string-allocate n)
(full-string-allocate n))))))
(do ((parts parts (cdr parts))
- (i 0 (string-copy! result i (caar parts) 0 (cdar parts))))
- ((not (pair? parts))))
+ (i 0 (fix:+ i (cdar parts))))
+ ((not (pair? parts)))
+ (string-copy! result i (caar parts) 0 (cdar parts)))
result))
\f
(define (string-copy! to at from #!optional start end)