io: fix file-buffer performance when driven by peeks
This commit is contained in:
parent
75c8c3ce37
commit
4d43c9884c
|
@ -121,9 +121,8 @@
|
|||
v))
|
||||
|
||||
(define/who (peek-byte [orig-in (current-input-port)] [skip-k 0])
|
||||
(check who input-port? orig-in)
|
||||
(check who exact-nonnegative-integer? skip-k)
|
||||
(let ([in (->core-input-port orig-in)])
|
||||
(let ([in (->core-input-port orig-in who)])
|
||||
(check who exact-nonnegative-integer? skip-k)
|
||||
(peek-a-byte who in skip-k)))
|
||||
|
||||
(define/who (peek-bytes amt skip-k [in (current-input-port)])
|
||||
|
|
|
@ -72,7 +72,10 @@
|
|||
(cond
|
||||
[(end-pos . fx< . (bytes-length bstr))
|
||||
;; add to end of buffer
|
||||
(pull-some-bytes amt end-pos pos)]
|
||||
(define pull-amt (if (eq? 'block buffer-mode)
|
||||
(fx- (bytes-length bstr) end-pos)
|
||||
amt))
|
||||
(pull-some-bytes pull-amt end-pos pos)]
|
||||
[(fx= pos 0)
|
||||
;; extend buffer
|
||||
(define new-bstr (make-bytes (fx* 2 (bytes-length bstr))))
|
||||
|
@ -170,6 +173,8 @@
|
|||
(define amt (min (fx- peeked-amt skip) (fx- end start)))
|
||||
(define s-pos (fx+ s skip))
|
||||
(bytes-copy! dest-bstr start bstr s-pos (fx+ s-pos amt))
|
||||
(unless progress-sema
|
||||
(fast-mode! 0))
|
||||
amt]
|
||||
[peeked-eof?
|
||||
eof]
|
||||
|
|
Loading…
Reference in New Issue
Block a user