- (multiple-value-bind (chars done)
- (funcall-stm-handler j-read-chars encap cbuf
- #\Newline index (length cbuf) t)
- (declare (type sb-int:index chars))
- (incf index chars)
- (incf total chars)
- (when (and (eq done :eof) (zerop total))
- (if eof-error-p
- (error 'end-of-file :stream stream)
- (return (values eof-value t))))
- (when done
- ;; If there's only one buffer in use, return it directly
- (when (null (cdr bufs))
- (return (values (sb-kernel:shrink-vector cbuf total)
- (eq done :eof))))
- ;; If total fits in final buffer, use it
- (when (<= total (length cbuf))
- (replace cbuf cbuf :start1 (- total index) :end2 index)
- (let ((idx 0))
- (declare (type sb-int:index idx))
- (do ((list bufs (cdr list)))
- ((eq list tail))
- (let ((buf (car list)))
- (declare (type simple-base-string buf))
- (replace cbuf buf :start1 idx)
- (incf idx (length buf)))))
- (return (values (sb-kernel:shrink-vector cbuf total)
- (eq done :eof))))
- ;; Allocate new string of appropriate length
- (let ((string (make-string total))
- (index 0))
- (declare (type sb-int:index index))
- (dolist (buf bufs)
- (declare (type simple-base-string buf))
- (replace string buf :start1 index)
- (incf index (length buf)))
- (return (values string (eq done :eof)))))
- (when (>= index (length cbuf))
- (setf cbuf (make-string (the sb-int:index (* 2 index))))
- (setf index 0)
- (setf (cdr tail) (cons cbuf nil))
- (setf tail (cdr tail))))))))
+ (multiple-value-bind (chars done)
+ (funcall-stm-handler j-read-chars encap cbuf
+ #\Newline index (length cbuf) t)
+ (declare (type sb-int:index chars))
+ (incf index chars)
+ (incf total chars)
+ (when (and (eq done :eof) (zerop total))
+ (if eof-error-p
+ (error 'end-of-file :stream stream)
+ (return (values eof-value t))))
+ (when done
+ ;; If there's only one buffer in use, return it directly
+ (when (null (cdr bufs))
+ (return (values (sb-kernel:shrink-vector cbuf total)
+ (eq done :eof))))
+ ;; If total fits in final buffer, use it
+ (when (<= total (length cbuf))
+ (replace cbuf cbuf :start1 (- total index) :end2 index)
+ (let ((idx 0))
+ (declare (type sb-int:index idx))
+ (do ((list bufs (cdr list)))
+ ((eq list tail))
+ (let ((buf (car list)))
+ (declare (type simple-string buf))
+ (replace cbuf buf :start1 idx)
+ (incf idx (length buf)))))
+ (return (values (sb-kernel:shrink-vector cbuf total)
+ (eq done :eof))))
+ ;; Allocate new string of appropriate length
+ (let ((string (make-string total))
+ (index 0))
+ (declare (type sb-int:index index))
+ (dolist (buf bufs)
+ (declare (type simple-string buf))
+ (replace string buf :start1 index)
+ (incf index (length buf)))
+ (return (values string (eq done :eof)))))
+ (when (>= index (length cbuf))
+ (setf cbuf (make-string (the sb-int:index (* 2 index))))
+ (setf index 0)
+ (setf (cdr tail) (cons cbuf nil))
+ (setf tail (cdr tail))))))))