mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-08 13:37:33 +02:00
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:
parent
4b082da588
commit
d03258c83a
2 changed files with 22 additions and 8 deletions
14
runtime.c
14
runtime.c
|
@ -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
|
||||
if (p->mem_buf[p->buf_idx] == '@') {
|
||||
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->col_num++;
|
||||
return_thread_runnable(data, unquote_splicing);
|
||||
return_thread_runnable(data, &vec);
|
||||
} else {
|
||||
// Again, special encoding for syntax
|
||||
make_c_opaque(opq, obj_char2obj(c));
|
||||
|
@ -6284,7 +6289,12 @@ void Cyc_io_read_token(void *data, object cont, object port)
|
|||
continue;
|
||||
} else if (c == ';') { // Datum comment
|
||||
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 {
|
||||
char buf[31];
|
||||
snprintf(buf, 30, "Unhandled input sequence %c", c);
|
||||
|
|
|
@ -164,6 +164,16 @@
|
|||
(if (vector-ref token 2)
|
||||
(exact (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
|
||||
(error (vector-ref token 0)))
|
||||
(else
|
||||
|
@ -186,12 +196,6 @@
|
|||
(apply bytevector (reverse lis)))
|
||||
(else
|
||||
(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
|
||||
token))))
|
||||
))
|
||||
|
|
Loading…
Add table
Reference in a new issue