From 5d3a9726b96dbc2e475c82dd49303cfa3232b9a4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 30 Jan 2025 21:54:47 -0800 Subject: get-csv: further get-char optimization. Another 5-6% gained form this. * stream.c (us_get_char, us_unget_char): Static functions removed. (get_csv): Retrieve the get_char and unget_char pointers from the strm_ops structure outside of the loop, and then just call these pointers. Careful: the unget_char virtual has reversed parameters compared to the global function. --- stream.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'stream.c') diff --git a/stream.c b/stream.c index a2fe74ef..2ebb0a2d 100644 --- a/stream.c +++ b/stream.c @@ -3086,12 +3086,6 @@ val get_char(val stream_in) return ops->get_char(stream); } -static val us_get_char(val stream) -{ - struct strm_ops *ops = coerce(struct strm_ops *, stream->co.ops); - return ops->get_char(stream); -} - val get_byte(val stream_in) { val self = lit("get-byte"); @@ -3120,12 +3114,6 @@ val unget_char(val ch, val stream_in) return ops->unget_char(stream, ch); } -static val us_unget_char(val ch, val stream) -{ - struct strm_ops *ops = coerce(struct strm_ops *, stream->co.ops); - return ops->unget_char(stream, ch); -} - val unget_byte(val byte, val stream_in) { val self = lit("unget-byte"); @@ -5442,19 +5430,22 @@ val get_csv(val source_opt) if3(stringp(source_opt), make_string_input_stream(source_opt), (class_check(self, source_opt, stream_cls), source_opt))); + struct strm_ops *ops = coerce(struct strm_ops *, source->co.ops); + val (*get_char)(val) = ops->get_char; + val (*unget_char)(val, val) = ops->unget_char; val record = nil, field = nil; enum { init, rfield, qfield, quot } state = init; int done = 0; while (!done) { - val ch = us_get_char(source); + val ch = get_char(source); if (ch == chr('\r')) { - val ch2 = us_get_char(source); + val ch2 = get_char(source); if (ch2 == chr('\n')) ch = ch2; else if (ch2) - us_unget_char(ch2, source); + unget_char(source, ch2); } else if (ch == nil) { if (state == init) return nil; -- cgit v1.2.3