From 54478e50f5aaad850bcfc4a435ee5f56f6eef797 Mon Sep 17 00:00:00 2001 From: Joe Marshall Date: Mon, 23 Nov 2009 18:02:19 -0800 Subject: [PATCH] Add fast read-char and peek-char. --- src/runtime/input.scm | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/runtime/input.scm b/src/runtime/input.scm index c7bc8e7cd..966c06e76 100644 --- a/src/runtime/input.scm +++ b/src/runtime/input.scm @@ -26,19 +26,26 @@ USA. ;;;; Input ;;; package: (runtime input-port) -(declare (usual-integrations)) +(declare (usual-integrations) + (integrate-external "port")) ;;;; Low level (define (input-port/char-ready? port) ((port/operation/char-ready? port) port)) +(define-integrable (input-port/%read-char port) + ((port/%operation/read-char port) port)) + (define (input-port/read-char port) ((port/operation/read-char port) port)) (define (input-port/unread-char port char) ((port/operation/unread-char port) port char)) +(define-integrable (input-port/%peek-char port) + ((port/%operation/peek-char port) port)) + (define (input-port/peek-char port) ((port/operation/peek-char port) port)) @@ -143,21 +150,25 @@ USA. (else #f)))) (input-port/char-ready? port)))) +(define (%read-char port) + (let loop () + (or (input-port/%read-char port) + (loop)))) + (define (read-char #!optional port) - (let ((port (optional-input-port port 'READ-CHAR))) - (let loop () - (or (input-port/read-char port) - (loop))))) + (%read-char (optional-input-port port 'READ-CHAR))) (define (unread-char char #!optional port) (guarantee-char char 'UNREAD-CHAR) (input-port/unread-char (optional-input-port port 'UNREAD-CHAR) char)) +(define (%peek-char port) + (let loop () + (or (input-port/%peek-char port) + (loop)))) + (define (peek-char #!optional port) - (let ((port (optional-input-port port 'PEEK-CHAR))) - (let loop () - (or (input-port/peek-char port) - (loop))))) + (%peek-char (optional-input-port port 'PEEK-CHAR))) (define (read-char-no-hang #!optional port) (let ((port (optional-input-port port 'READ-CHAR-NO-HANG))) -- 2.25.1