From 7fef3c0d7cdad433fbf614ad4b5c30b7f99814c8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 22 Apr 2020 06:42:32 -0700 Subject: parser: batched read operation for speed. As a result of this change, the startup time is reduced. The command txr -e '(compile-toplevel nil)' shows a 54% speedup: around 110 milliseconds down from around 170. Programs that read large amounts of TXR Lisp data will benefit. * parser.l (YY_INPUT): Use new get_bytes function instead of get_byte to read a buffer at a time. * stream.c (get_bytes): New function. * stream.h (get_bytes): Declared. --- parser.l | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'parser.l') diff --git a/parser.l b/parser.l index 87215221..52f30f2f 100644 --- a/parser.l +++ b/parser.l @@ -52,13 +52,11 @@ #include "parser.h" #include "txr.h" -#define YY_INPUT(buf, result, max_size) \ - do { \ - val c = get_byte(yyextra->stream); \ - int n = 0; \ - if (c) \ - buf[n++] = convert(char, c_num(c)); \ - result = n; \ +#define YY_INPUT(buf, result, max_size) \ + do { \ + val n = get_bytes(lit("parser"), yyextra->stream, \ + convert(mem_t *, buf), max_size); \ + result = c_num(n); \ } while (0) #define YY_DECL \ -- cgit v1.2.3