mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 22:10:21 +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:
parent
1852633a9b
commit
fd5e69d3c1
1 changed files with 17 additions and 7 deletions
|
@ -384,10 +384,16 @@
|
||||||
(peek-bytes port 1 fast-path
|
(peek-bytes port 1 fast-path
|
||||||
(lambda (buf bv cur buffered) (slow-path))))
|
(lambda (buf bv cur buffered) (slow-path))))
|
||||||
|
|
||||||
(define* (read-char #:optional (port (current-input-port)))
|
(define-inlinable (port-advance-position! port char)
|
||||||
(define (update-position! 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
|
(case char
|
||||||
((#\alarm) #t) ; No change.
|
((#\alarm) #t) ; No change.
|
||||||
((#\backspace)
|
((#\backspace)
|
||||||
(let ((col (port-column port)))
|
(let ((col (port-column port)))
|
||||||
(when (> col 0)
|
(when (> col 0)
|
||||||
|
@ -401,7 +407,11 @@
|
||||||
(let ((col (port-column port)))
|
(let ((col (port-column port)))
|
||||||
(set-port-column! port (- (+ col 8) (remainder col 8)))))
|
(set-port-column! port (- (+ col 8) (remainder col 8)))))
|
||||||
(else
|
(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)
|
char)
|
||||||
(define (slow-path)
|
(define (slow-path)
|
||||||
(call-with-values (lambda () (peek-char-and-len port))
|
(call-with-values (lambda () (peek-char-and-len port))
|
||||||
|
@ -412,7 +422,7 @@
|
||||||
(begin
|
(begin
|
||||||
(set-port-buffer-has-eof?! buf #f)
|
(set-port-buffer-has-eof?! buf #f)
|
||||||
char)
|
char)
|
||||||
(update-position! char))))))
|
(finish char))))))
|
||||||
(define (fast-path buf bv cur buffered)
|
(define (fast-path buf bv cur buffered)
|
||||||
(let ((u8 (bytevector-u8-ref bv cur))
|
(let ((u8 (bytevector-u8-ref bv cur))
|
||||||
(enc (%port-encoding port)))
|
(enc (%port-encoding port)))
|
||||||
|
@ -421,11 +431,11 @@
|
||||||
(decode-utf8 bv cur buffered u8
|
(decode-utf8 bv cur buffered u8
|
||||||
(lambda (char len)
|
(lambda (char len)
|
||||||
(set-port-buffer-cur! buf (+ cur len))
|
(set-port-buffer-cur! buf (+ cur len))
|
||||||
(update-position! char))
|
(finish char))
|
||||||
slow-path))
|
slow-path))
|
||||||
((ISO-8859-1)
|
((ISO-8859-1)
|
||||||
(set-port-buffer-cur! buf (+ cur 1))
|
(set-port-buffer-cur! buf (+ cur 1))
|
||||||
(update-position! (integer->char u8)))
|
(finish (integer->char u8)))
|
||||||
(else (slow-path)))))
|
(else (slow-path)))))
|
||||||
(peek-bytes port 1 fast-path
|
(peek-bytes port 1 fast-path
|
||||||
(lambda (buf bv cur buffered) (slow-path))))
|
(lambda (buf bv cur buffered) (slow-path))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue