diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-04-20 06:30:36 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-04-20 06:30:36 -0700 |
commit | 814b1a284fc22feb9444f2195a36c57cbacd84aa (patch) | |
tree | 2d452a5528667d95f7bb71a99d4b84a490f0836e | |
parent | c636a168cd57ca5db253db7a0907f06621a6991e (diff) | |
download | txr-814b1a284fc22feb9444f2195a36c57cbacd84aa.tar.gz txr-814b1a284fc22feb9444f2195a36c57cbacd84aa.tar.bz2 txr-814b1a284fc22feb9444f2195a36c57cbacd84aa.zip |
Recycle conses in unget-char and read-until-match.
* regex.c (ead_until_match): Use rcyc_pop instead of pop
to move the conses to the recycle list. We know these
are not shared with anything. Adding additional logic
to completely recycle the stack.
* socket.c (dgram_get_char): Use rcyc_pop to
get the character from the push-back list.
* stream.c (stdio_get_char): Likewise.
-rw-r--r-- | regex.c | 10 | ||||
-rw-r--r-- | socket.c | 2 | ||||
-rw-r--r-- | stream.c | 2 |
3 files changed, 9 insertions, 5 deletions
@@ -2554,7 +2554,7 @@ val read_until_match(val regex, val stream_in, val include_match_in) goto out_match; while (stack) - unget_char(pop(&stack), stream); + unget_char(rcyc_pop(&stack), stream); ch = get_char(stream); @@ -2580,14 +2580,18 @@ val read_until_match(val regex, val stream_in, val include_match_in) if (nil) { out_match: while (stack != match) - unget_char(pop(&stack), stream); + unget_char(rcyc_pop(&stack), stream); if (!out) out = null_string; if (include_match) - out = cat_str(cons(out, nreverse(stack)), nil); + out = cat_str(cons(out, stack = nreverse(stack)), nil); } regex_machine_cleanup(®m); + + while (stack) + rcyc_pop(&stack); + return out; } @@ -436,7 +436,7 @@ static val dgram_get_char(val stream) struct dgram_stream *d = coerce(struct dgram_stream *, stream->co.handle); if (d->unget_c) { - return pop(&d->unget_c); + return rcyc_pop(&d->unget_c); } else { wint_t ch = utf8_decode(&d->ud, dgram_get_byte_callback, coerce(mem_t *, d)); @@ -685,7 +685,7 @@ static val stdio_get_char(val stream) struct stdio_handle *h = coerce(struct stdio_handle *, stream->co.handle); if (h->unget_c) - return pop(&h->unget_c); + return rcyc_pop(&h->unget_c); if (h->f) { wint_t ch = utf8_decode(&h->ud, stdio_get_char_callback, |