1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 05:50:26 +02:00

Sports refactor

* module/ice-9/sports.scm (port-advance-position!): Factor out to a
  helper.
  (read-char): Use port-advance-position!.
This commit is contained in:
Andy Wingo 2016-05-22 13:42:00 +02:00
parent 1852633a9b
commit fd5e69d3c1

View file

@ -384,8 +384,14 @@
(peek-bytes port 1 fast-path
(lambda (buf bv cur buffered) (slow-path))))
(define* (read-char #:optional (port (current-input-port)))
(define (update-position! char)
(define-inlinable (port-advance-position! port char)
;; FIXME: this cond is a speed hack; really we should just compile
;; `case' better.
(cond
;; FIXME: char>? et al should compile well.
((<= (char->integer #\space) (char->integer char))
(set-port-column! port (1+ (port-column port))))
(else
(case char
((#\alarm) #t) ; No change.
((#\backspace)
@ -401,7 +407,11 @@
(let ((col (port-column port)))
(set-port-column! port (- (+ col 8) (remainder col 8)))))
(else
(set-port-column! port (1+ (port-column port)))))
(set-port-column! port (1+ (port-column port))))))))
(define* (read-char #:optional (port (current-input-port)))
(define (finish char)
(port-advance-position! port char)
char)
(define (slow-path)
(call-with-values (lambda () (peek-char-and-len port))
@ -412,7 +422,7 @@
(begin
(set-port-buffer-has-eof?! buf #f)
char)
(update-position! char))))))
(finish char))))))
(define (fast-path buf bv cur buffered)
(let ((u8 (bytevector-u8-ref bv cur))
(enc (%port-encoding port)))
@ -421,11 +431,11 @@
(decode-utf8 bv cur buffered u8
(lambda (char len)
(set-port-buffer-cur! buf (+ cur len))
(update-position! char))
(finish char))
slow-path))
((ISO-8859-1)
(set-port-buffer-cur! buf (+ cur 1))
(update-position! (integer->char u8)))
(finish (integer->char u8)))
(else (slow-path)))))
(peek-bytes port 1 fast-path
(lambda (buf bv cur buffered) (slow-path))))