From 5a619e1986724cf8e27b637509925a8da36837e8 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 19 Jan 2017 21:08:19 +0200 Subject: Speed up programs that toggle IGNORECASE a lot. --- io.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 688723fd..d65f2aaa 100644 --- a/io.c +++ b/io.c @@ -318,8 +318,7 @@ static long read_default_timeout; static struct redirect *red_head = NULL; static NODE *RS = NULL; -static Regexp *RS_re_yes_case; /* regexp for RS when ignoring case */ -static Regexp *RS_re_no_case; /* regexp for RS when not ignoring case */ +static Regexp *RS_re[2]; /* index 0 - don't ignore case, index 1, do */ static Regexp *RS_regexp; static const char nonfatal[] = "NONFATAL"; @@ -3870,7 +3869,7 @@ set_RS() * set_IGNORECASE() relies on this routine to call * set_FS(). */ - RS_regexp = (IGNORECASE ? RS_re_no_case : RS_re_yes_case); + RS_regexp = RS_re[IGNORECASE]; goto set_FS; } unref(save_rs); @@ -3882,9 +3881,9 @@ set_RS() * Please do not remerge the if condition; hinders memory deallocation * in case of fatal error in make_regexp. */ - refree(RS_re_yes_case); /* NULL argument is ok */ - refree(RS_re_no_case); - RS_re_yes_case = RS_re_no_case = RS_regexp = NULL; + refree(RS_re[0]); /* NULL argument is ok */ + refree(RS_re[1]); + RS_re[0] = RS_re[1] = RS_regexp = NULL; if (RS->stlen == 0) { RS_is_null = true; @@ -3892,9 +3891,9 @@ set_RS() } else if (RS->stlen > 1 && ! do_traditional) { static bool warned = false; - RS_re_yes_case = make_regexp(RS->stptr, RS->stlen, false, true, true); - RS_re_no_case = make_regexp(RS->stptr, RS->stlen, true, true, true); - RS_regexp = (IGNORECASE ? RS_re_no_case : RS_re_yes_case); + RS_re[0] = make_regexp(RS->stptr, RS->stlen, false, true, true); + RS_re[1] = make_regexp(RS->stptr, RS->stlen, true, true, true); + RS_regexp = RS_re[IGNORECASE]; matchrec = rsrescan; -- cgit v1.2.3