don't block for bytes that might not be needed

svn: r4031
This commit is contained in:
Matthew Flatt 2006-08-12 03:02:46 +00:00
parent 786bfdab30
commit 21939a881d

View File

@ -271,19 +271,16 @@
(READBITS n)))
(define (READBITS n)
(if (= buf-pos buf-max)
(if (and (buf-max . < . BUFFER-SIZE)
(positive? buf-max))
(error 'inflate "unexpected end of file")
(begin
(when (positive? buf-max)
(read-bytes! buffer input-port 0 (- buf-max MAX-LOOKAHEAD))
; (bytes-copy! buffer 0 buffer (- buf-max MAX-LOOKAHEAD) buf-max)
(set! buf-pos MAX-LOOKAHEAD))
(let ([got (peek-bytes! buffer buf-pos input-port buf-pos BUFFER-SIZE)])
(if (eof-object? got)
(error 'inflate "unexpected end of file")
(set! buf-max (+ buf-pos got))))
(READBITS n)))
(begin
(when (positive? buf-max)
(read-bytes! buffer input-port 0 (- buf-max MAX-LOOKAHEAD))
; (bytes-copy! buffer 0 buffer (- buf-max MAX-LOOKAHEAD) buf-max)
(set! buf-pos MAX-LOOKAHEAD))
(let ([got (peek-bytes-avail! buffer buf-pos #f input-port buf-pos BUFFER-SIZE)])
(if (eof-object? got)
(error 'inflate "unexpected end of file")
(set! buf-max (+ buf-pos got))))
(READBITS n))
(let ([v (bytes-ref buffer buf-pos)])
(set! buf-pos (add1 buf-pos))
(set! bb (+ bb (arithmetic-shift v bk)))