From 814b1a284fc22feb9444f2195a36c57cbacd84aa Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 20 Apr 2016 06:30:36 -0700 Subject: 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. --- regex.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'regex.c') diff --git a/regex.c b/regex.c index e8de118c..faf38965 100644 --- a/regex.c +++ b/regex.c @@ -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; } -- cgit v1.2.3