bytevector-length
bytevector-u8-ref
bytevector-u8-set!
+ (lambda (bv) bv)
16
bytevector-builder:finish-build)))
(lambda (#!optional object)
;;;; Builder for vector-like sequences
(define (make-sequence-builder make-sequence sequence-length sequence-ref
- sequence-set! buffer-length finish-build)
+ sequence-set! sequence-copy buffer-length
+ finish-build)
;; This is optimized to minimize copying, so it wastes some space.
(let ((buffers)
(buffer)
(begin
(if (fix:> index 0)
(new-buffer!))
- (set! buffers (cons (cons sequence length) buffers))
+ (set! buffers
+ (cons (cons (sequence-copy sequence) length)
+ buffers))
unspecific))))
(define (build)
(with-output-to-port port thunk))))
\f
(define (open-output-string)
- (make-textual-port string-output-type (make-ostate (string-builder) 0)))
+ (make-textual-port string-output-type
+ (make-ostate (string-builder 'copy? #t) 0)))
(define-structure ostate
(builder #f read-only #t)
(define (string-out/write-substring port string start end)
(let ((os (textual-port-state port))
(n (fix:- end start)))
- ((ostate-builder os) (string-copy string start end))
+ ((ostate-builder os) (string-slice string start end))
(update-column-for-substring! os string start end)
n))
(else (error "Not a char or string:" object)))))))
(define (make-string-builder options)
- (receive (buffer-length ->nfc?)
+ (receive (buffer-length ->nfc? copy?)
(string-builder-options options 'string-builder)
(let ((tracker (max-cp-tracker)))
(combine-tracker-and-builder
string-length
string-ref
string-set!
+ (if copy? string-copy (lambda (s) s))
buffer-length
(string-builder-finish ->nfc? (tracker 'get)))))))
(define-deferred string-builder-options
(keyword-option-parser
(list (list 'buffer-length positive-fixnum? 16)
- (list '->nfc? boolean? #t))))
+ (list '->nfc? boolean? #t)
+ (list 'copy? boolean? #f))))
\f
(define (max-cp-tracker)
(let ((max-cp 0))