Make read a little faster by streamlining main path

Move 2 comparisons underneath the (vector?) case, so in the normal case they can be skipped.
This commit is contained in:
Justin Ethier 2017-08-23 17:26:20 +00:00
parent 4b082da588
commit d03258c83a
2 changed files with 22 additions and 8 deletions

View file

@ -6213,9 +6213,14 @@ void Cyc_io_read_token(void *data, object cont, object port)
_read_next_char(data, cont, p); // Do another buffer read if needed _read_next_char(data, cont, p); // Do another buffer read if needed
if (p->mem_buf[p->buf_idx] == '@') { if (p->mem_buf[p->buf_idx] == '@') {
object unquote_splicing = find_or_add_symbol(",@"); object unquote_splicing = find_or_add_symbol(",@");
make_empty_vector(vec);
vec.num_elements = 2;
vec.elements = (object *) alloca(sizeof(object) * vec.num_elements);
vec.elements[0] = unquote_splicing;
vec.elements[1] = boolean_f;
p->buf_idx++; p->buf_idx++;
p->col_num++; p->col_num++;
return_thread_runnable(data, unquote_splicing); return_thread_runnable(data, &vec);
} else { } else {
// Again, special encoding for syntax // Again, special encoding for syntax
make_c_opaque(opq, obj_char2obj(c)); make_c_opaque(opq, obj_char2obj(c));
@ -6284,7 +6289,12 @@ void Cyc_io_read_token(void *data, object cont, object port)
continue; continue;
} else if (c == ';') { // Datum comment } else if (c == ';') { // Datum comment
object sym = find_or_add_symbol("#;"); object sym = find_or_add_symbol("#;");
return_thread_runnable(data, sym); make_empty_vector(vec);
vec.num_elements = 2;
vec.elements = (object *) alloca(sizeof(object) * vec.num_elements);
vec.elements[0] = sym;
vec.elements[1] = boolean_f;
return_thread_runnable(data, &vec);
} else { } else {
char buf[31]; char buf[31];
snprintf(buf, 30, "Unhandled input sequence %c", c); snprintf(buf, 30, "Unhandled input sequence %c", c);

View file

@ -164,6 +164,16 @@
(if (vector-ref token 2) (if (vector-ref token 2)
(exact (string->number (vector-ref token 0) (vector-ref token 1))) (exact (string->number (vector-ref token 0) (vector-ref token 1)))
(inexact (string->number (vector-ref token 0) (vector-ref token 1))))) (inexact (string->number (vector-ref token 0) (vector-ref token 1)))))
((= (vector-length token) 2) ;; Special case: special symbols
(let ((t (vector-ref token 0)))
(cond
((eq? t *sym-unquote-splicing*)
(list 'unquote-splicing (parse fp)))
((eq? t *sym-datum-comment*)
(parse fp) ;; Ignore next datum
(parse fp))
(else
(error "Unexpected token" t)))))
((= (vector-length token) 1) ;; Special case: error ((= (vector-length token) 1) ;; Special case: error
(error (vector-ref token 0))) (error (vector-ref token 0)))
(else (else
@ -186,12 +196,6 @@
(apply bytevector (reverse lis))) (apply bytevector (reverse lis)))
(else (else
(loop (cons t lis) (parse fp)))))) (loop (cons t lis) (parse fp))))))
((eq? token *sym-unquote-splicing*)
(list 'unquote-splicing (parse fp)))
((eq? token *sym-datum-comment*)
(parse fp) ;; Ignore next datum
(parse fp))
;; Other special cases?
(else (else
token)))) token))))
)) ))