restoring efficient read-line

This commit is contained in:
Alex Shinn 2019-01-27 22:10:35 +08:00
parent e9ce08da78
commit ef0a8bd199
3 changed files with 24 additions and 18 deletions

View file

@ -75,9 +75,11 @@
;;> a string not including the newline. Reads at most \var{n} ;;> a string not including the newline. Reads at most \var{n}
;;> characters, defaulting to 8192. ;;> characters, defaulting to 8192.
(cond-expand (define (%read-line n in)
((not string-streams) (cond
(define (%read-line n in) ((port-fileno in)
(%%read-line n in))
(else
(let ((out (open-output-string))) (let ((out (open-output-string)))
(let lp ((i 0)) (let lp ((i 0))
(let ((ch (peek-char in))) (let ((ch (peek-char in)))
@ -128,9 +130,11 @@
;;> than \var{n} characters if the end of file is reached, ;;> than \var{n} characters if the end of file is reached,
;;> or the eof-object if no characters are available. ;;> or the eof-object if no characters are available.
(cond-expand (define (%read-string n in)
((not string-streams) (cond
(define (%read-string n in) ;;((port-fileno in)
;; (%%read-string n in))
(else
(let ((out (open-output-string))) (let ((out (open-output-string)))
(let lp ((i 0)) (let lp ((i 0))
(cond ((or (= i n) (eof-object? (peek-char in))) (cond ((or (= i n) (eof-object? (peek-char in)))
@ -159,9 +163,11 @@
;;> An error is signalled if the length of \var{str} is smaller ;;> An error is signalled if the length of \var{str} is smaller
;;> than \var{n}. ;;> than \var{n}.
(cond-expand (define (%read-string! str n in)
((not string-streams) (cond
(define (%read-string! str n in) ;;((port-fileno in)
;; (%%read-string! str n in))
(else
(let lp ((i 0)) (let lp ((i 0))
(cond ((or (= i n) (eof-object? (peek-char in))) i) (cond ((or (= i n) (eof-object? (peek-char in))) i)
(else (string-set! str i (read-char in)) (lp (+ i 1)))))))) (else (string-set! str i (read-char in)) (lp (+ i 1))))))))

View file

@ -1,15 +1,12 @@
(cond-expand (define-c non-null-string (%%read-line "fgets")
(string-streams
(define-c non-null-string (%read-line "fgets")
((result (array char arg1)) int (default (current-input-port) input-port))) ((result (array char arg1)) int (default (current-input-port) input-port)))
(define-c size_t (%read-string "fread") ;;(define-c size_t (%%read-string "fread")
((result (array char (result arg2))) (value 1 size_t) size_t (default (current-input-port) input-port))) ;; ((result (array char (result arg2))) (value 1 size_t) size_t (default (current-input-port) input-port)))
(define-c size_t (%read-string! "fread") ;;(define-c size_t (%%read-string! "fread")
(string (value 1 size_t) size_t (default (current-input-port) input-port))) ;; (string (value 1 size_t) size_t (default (current-input-port) input-port)))
))
(c-include-verbatim "port.c") (c-include-verbatim "port.c")

3
sexp.c
View file

@ -482,6 +482,9 @@ static const char* sexp_initial_features[] = {
#if SEXP_USE_UTF8_STRINGS #if SEXP_USE_UTF8_STRINGS
"full-unicode", "full-unicode",
#endif #endif
#if SEXP_USE_STRING_INDEX_TABLE
"string-index",
#endif
#if SEXP_USE_GREEN_THREADS #if SEXP_USE_GREEN_THREADS
"threads", "threads",
#endif #endif