summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-01-30 21:54:47 -0800
committerKaz Kylheku <kaz@kylheku.com>2025-01-30 21:54:47 -0800
commit5d3a9726b96dbc2e475c82dd49303cfa3232b9a4 (patch)
treedcc273e512988e53d8402279b10e5644c1451bc5
parent6f8115f23d0cb4225cd652abad65557d5fe7ffd9 (diff)
downloadtxr-5d3a9726b96dbc2e475c82dd49303cfa3232b9a4.tar.gz
txr-5d3a9726b96dbc2e475c82dd49303cfa3232b9a4.tar.bz2
txr-5d3a9726b96dbc2e475c82dd49303cfa3232b9a4.zip
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.
-rw-r--r--stream.c21
1 files changed, 6 insertions, 15 deletions
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;