summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-08-12 07:35:03 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-08-12 07:48:18 -0700
commit5700656ed2ec6a93e0a5c825b445f639d21a0d6e (patch)
tree17139c396b32f05cc839a91a0aa2909f199b579b /src
parentc797046c7c13c2647182b919a79a4c5b4ecf82b1 (diff)
downloadgrep-5700656ed2ec6a93e0a5c825b445f639d21a0d6e.tar.gz
dfa: optimize [x-x]
* src/dfa.c (parse_bracket_exp): Treat [x-x] as if it were [x]. This also pacifies GCC, which otherwise complains about wc2 being set but not used.
Diffstat (limited to 'src')
-rw-r--r--src/dfa.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/dfa.c b/src/dfa.c
index 18c86d72..ac5129b4 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -1101,41 +1101,49 @@ parse_bracket_exp (void)
c2 = ']';
}
- if (c2 != ']')
+ if (c2 == ']')
+ {
+ /* In the case [x-], the - is an ordinary hyphen,
+ which is left in c1, the lookahead character. */
+ lexptr -= cur_mb_len;
+ lexleft += cur_mb_len;
+ }
+ else
{
if (c2 == '\\' && (syntax_bits & RE_BACKSLASH_ESCAPE_IN_LISTS))
FETCH_WC (c2, wc2, _("unbalanced ["));
- if (dfa->multibyte)
- known_bracket_exp = false;
- else if (using_simple_locale ())
+ colon_warning_state |= 8;
+ FETCH_WC (c1, wc1, _("unbalanced ["));
+
+ /* Treat [x-y] as a range if x != y. */
+ if (wc != wc2 || wc == WEOF)
{
- for (c1 = c; c1 <= c2; c1++)
- setbit (c1, ccl);
- if (case_fold)
+ if (dfa->multibyte)
+ known_bracket_exp = false;
+ else if (using_simple_locale ())
{
- int uc = toupper (c);
- int uc2 = toupper (c2);
- for (c1 = 0; c1 < NOTCHAR; c1++)
+ int ci;
+ for (ci = c; ci <= c2; ci++)
+ setbit (ci, ccl);
+ if (case_fold)
{
- int uc1 = toupper (c1);
- if (uc <= uc1 && uc1 <= uc2)
- setbit (c1, ccl);
+ int uc = toupper (c);
+ int uc2 = toupper (c2);
+ for (ci = 0; ci < NOTCHAR; ci++)
+ {
+ int uci = toupper (ci);
+ if (uc <= uci && uci <= uc2)
+ setbit (ci, ccl);
+ }
}
}
- }
- else
- known_bracket_exp = false;
+ else
+ known_bracket_exp = false;
- colon_warning_state |= 8;
- FETCH_WC (c1, wc1, _("unbalanced ["));
- continue;
+ continue;
+ }
}
-
- /* In the case [x-], the - is an ordinary hyphen,
- which is left in c1, the lookahead character. */
- lexptr -= cur_mb_len;
- lexleft += cur_mb_len;
}
colon_warning_state |= (c == ':') ? 2 : 4;