master: read-byte transform: refill the buffer instead of just calling n-bin

stassats via Sbcl-commits <[email protected]>
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  4727a49892c11ebe996753f4a6e420666ac9c065 (commit)
      from  ae55fe64435d4015b8d640532196885b3323d4a7 (commit)

- Log -----------------------------------------------------------------
commit 4727a49892c11ebe996753f4a6e420666ac9c065
Author: Stas Boukarev <[email protected]>
Date:   Fri Aug 7 22:40:04 2026 +0300

    read-byte transform: refill the buffer instead of just calling n-bin
    
    Which does not touch the buffer.
---
 src/compiler/fndb.lisp    |  3 +++
 src/compiler/srctran.lisp | 25 ++++++++++++++-----------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/compiler/fndb.lisp b/src/compiler/fndb.lisp
index 389e6a820..95f88562b 100644
--- a/src/compiler/fndb.lisp
+++ b/src/compiler/fndb.lisp
@@ -1789,6 +1789,9 @@
 (defknown read-byte (stream &optional t t) t ()
   :derive-type (read-elt-type-deriver nil 'integer nil))
 
+(defknown fast-read-byte-refill (stream t t) t ()
+  :derive-type (read-elt-type-deriver nil '(unsigned-byte 8) nil))
+
 (defknown (prin1 print princ) (t &optional stream-designator)
   t
   (any)
diff --git a/src/compiler/srctran.lisp b/src/compiler/srctran.lisp
index 9eeef6208..9c9416ae6 100644
--- a/src/compiler/srctran.lisp
+++ b/src/compiler/srctran.lisp
@@ -9480,20 +9480,23 @@
 (deftransform read-byte ((stream &optional eof-error-p eof-value))
   (delete-lvar-cast-if (specifier-type 'stream) stream)
   `(if (sb-impl::ansi-stream-p stream)
-       (let ((index (ansi-stream-in-index stream)))
-         ;; ANSI stream with no in-buffer must have IN-INDEX = +ANSI-STREAM-IN-BUFFER-LENGTH+
-         (if (/= index sb-impl::+ansi-stream-in-buffer-length+)
-             (prog1 (aref (truly-the vector (ansi-stream-in-buffer stream)) index)
-               (setf (ansi-stream-in-index stream) (1+ index)))
+       (let ((index (ansi-stream-in-index stream))
+             (buffer (ansi-stream-in-buffer stream)))
+         (if buffer
+             (if (/= index sb-impl::+ansi-stream-in-buffer-length+)
+                 (prog1 (aref (truly-the vector (ansi-stream-in-buffer stream)) index)
+                   (setf (ansi-stream-in-index stream) (1+ index)))
+                 (fast-read-byte-refill stream ,(if eof-error-p 'eof-error-p t)
+                                        eof-value))
              (funcall (ansi-stream-bin stream) stream ,(if eof-error-p 'eof-error-p t)
                       eof-value)))
        (locally (declare (notinline read-byte))
-           (read-byte stream
-                      ,@(loop for (lvar var) on (list eof-error-p 'eof-error-p
-                                                      eof-value 'eof-value)
-                              by #'cddr
-                              when lvar
-                              collect var)))))
+         (read-byte stream
+                    ,@(loop for (lvar var) on (list eof-error-p 'eof-error-p
+                                                    eof-value 'eof-value)
+                            by #'cddr
+                            when lvar
+                            collect var)))))
 
 (deftransform peek-char ((&optional peek-type stream eof-error-p eof-value recursive-p)
                          (null &rest t))

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.