guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 02/06: clear-stream-start-for-bom-read refactor


From: Andy Wingo
Subject: [Guile-commits] 02/06: clear-stream-start-for-bom-read refactor
Date: Tue, 10 May 2016 13:41:18 +0000 (UTC)

wingo pushed a commit to branch wip-port-refactor
in repository guile.

commit 0dd18191bc864a53230963ceb485d7815e058006
Author: Andy Wingo <address@hidden>
Date:   Tue May 10 15:36:31 2016 +0200

    clear-stream-start-for-bom-read refactor
    
    * module/ice-9/ports.scm (clear-stream-start-for-bom-read): Use the
      "buffered" value that fill-input returns.
---
 module/ice-9/ports.scm |   27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index 6078b6a..ad9c088 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -212,19 +212,20 @@ interpret its input and output."
 (define (clear-stream-start-for-bom-read port io-mode)
   (define (maybe-consume-bom bom)
     (and (eq? (peek-byte port) (bytevector-u8-ref bom 0))
-         (let* ((buf (fill-input port (bytevector-length bom)))
-                (bv (port-buffer-bytevector buf))
-                (cur (port-buffer-cur bv)))
-           (and (<= (bytevector-length bv)
-                    (- (port-buffer-end buf) cur))
-                (let lp ((i 1))
-                  (if (= i (bytevector-length bom))
-                      (begin
-                        (set-port-buffer-cur! buf (+ cur i))
-                        #t)
-                      (and (eq? (bytevector-u8-ref bv (+ cur i))
-                                (bytevector-u8-ref bom i))
-                           (lp (1+ i)))))))))
+         (call-with-values (lambda ()
+                             (fill-input port (bytevector-length bom)))
+           (lambda (buf buffered)
+             (and (<= (bytevector-length bom) buffered)
+                  (let ((bv (port-buffer-bytevector buf))
+                        (cur (port-buffer-cur buf)))
+                    (let lp ((i 1))
+                      (if (= i (bytevector-length bom))
+                          (begin
+                            (set-port-buffer-cur! buf (+ cur i))
+                            #t)
+                          (and (eq? (bytevector-u8-ref bv (+ cur i))
+                                    (bytevector-u8-ref bom i))
+                               (lp (1+ i)))))))))))
   (when (and (port-clear-stream-start-for-bom-read port)
              (eq? io-mode 'text))
     (case (%port-encoding port)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]