From a8067e8f899dc2842aba0780a6943bacb8247c8c Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 13 Nov 2003 21:23:11 +0000 Subject: [PATCH] Update. 2003-11-13 Jakub Jelinek * posix/regcomp.c (optimize_utf8): Optimize even if SIMPLE_BRACKET with no bits set for >= 0x80 chars is seen. * posix/bug-regex20.c (tests): Add new tests. Expect [ABC] to be optimized. (main): Run all tests with RE_ICASE as well. --- ChangeLog | 8 ++++++++ posix/bug-regex20.c | 44 ++++++++++++++++++++++++++++++++++++++++---- posix/regcomp.c | 8 +++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d99ae09..b146509 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-11-13 Jakub Jelinek + + * posix/regcomp.c (optimize_utf8): Optimize even if SIMPLE_BRACKET + with no bits set for >= 0x80 chars is seen. + * posix/bug-regex20.c (tests): Add new tests. Expect [ABC] to be + optimized. + (main): Run all tests with RE_ICASE as well. + 2003-11-13 Ulrich Drepper * posix/Makefile: Add rules to build and run tst-rxspencer. diff --git a/posix/bug-regex20.c b/posix/bug-regex20.c index 69f3fbe..11b9484 100644 --- a/posix/bug-regex20.c +++ b/posix/bug-regex20.c @@ -47,8 +47,8 @@ static struct {RE_SYNTAX_POSIX_BASIC, "^x\\\\y\\{6\\}z\\+", "x\\yyyyyyzz\xc3\xb6", 0, 1}, {RE_SYNTAX_POSIX_BASIC, "^x\\\\y\\{2,36\\}z\\+", "x\\yzz\xc3\xb6", -1, 1}, {RE_SYNTAX_POSIX_BASIC, "^x\\\\y\\{,3\\}z\\+", "x\\yyyzz\xc3\xb6", 0, 1}, - /* FIXME. This one should be optimizable, but is not ATM. */ - {RE_SYNTAX_POSIX_BASIC, "x[ABC]y", "axCy", 1, 0}, + {RE_SYNTAX_POSIX_BASIC, "x[C]y", "axCy", 1, 1}, + {RE_SYNTAX_POSIX_BASIC, "x[ABC]y", "axCy", 1, 1}, {RE_SYNTAX_POSIX_BASIC, "\\`x\\|z\\'", "x\xe2\x80\x94", 0, 1}, {RE_SYNTAX_POSIX_BASIC, "\\(xy\\)z\\1a\\1", "\xe2\x80\x94xyzxyaxy\xc3\x84", 3, 1}, {RE_SYNTAX_POSIX_BASIC, "xy\\?z", "\xc3\x84xz\xc3\xb6", 2, 1}, @@ -57,8 +57,8 @@ static struct {RE_SYNTAX_POSIX_EXTENDED, "^x\\\\y{6}z+", "x\\yyyyyyzz\xc3\xb6", 0, 1}, {RE_SYNTAX_POSIX_EXTENDED, "^x\\\\y{2,36}z+", "x\\yzz\xc3\xb6", -1, 1}, {RE_SYNTAX_POSIX_EXTENDED, "^x\\\\y{,3}z+", "x\\yyyzz\xc3\xb6", 0, 1}, - /* FIXME. This one should be optimizable, but is not ATM. */ - {RE_SYNTAX_POSIX_EXTENDED, "x[ABC]y", "axCy", 1, 0}, + {RE_SYNTAX_POSIX_EXTENDED, "x[C]y", "axCy", 1, 1}, + {RE_SYNTAX_POSIX_EXTENDED, "x[ABC]y", "axCy", 1, 1}, {RE_SYNTAX_POSIX_EXTENDED, "\\`x|z\\'", "x\xe2\x80\x94", 0, 1}, {RE_SYNTAX_POSIX_EXTENDED, "(xy)z\\1a\\1", "\xe2\x80\x94xyzxyaxy\xc3\x84", 3, 1}, {RE_SYNTAX_POSIX_EXTENDED, "xy?z", "\xc3\x84xz\xc3\xb6", 2, 1}, @@ -69,6 +69,8 @@ static struct {RE_SYNTAX_POSIX_BASIC, "x[A-Z,]y", "axCy", 1, 0}, {RE_SYNTAX_POSIX_BASIC, "x[^y]z", "ax\xe2\x80\x94z", 1, 0}, {RE_SYNTAX_POSIX_BASIC, "x[[:alnum:]]z", "ax\xc3\x96z", 1, 0}, + {RE_SYNTAX_POSIX_BASIC, "x[[=A=]]z", "axAz", 1, 0}, + {RE_SYNTAX_POSIX_BASIC, "x[[=\xc3\x84=]]z", "ax\xc3\x84z", 1, 0}, {RE_SYNTAX_POSIX_BASIC, "\\mb_cur_max == 1; + if (optimized) + { + printf ("pattern %zd optimized while it should not be when case insensitive\n", + i); + ret = 1; + } + + res = re_search (®buf, tests[i].string, strlen (tests[i].string), 0, + strlen (tests[i].string), NULL); + if (res != tests[i].res) + { + printf ("re_search %zd failed: %d\n", i, res); + ret = 1; + regfree (®buf); + continue; + } + regfree (®buf); } return ret; diff --git a/posix/regcomp.c b/posix/regcomp.c index a762859..9f56b38 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -964,7 +964,7 @@ static void optimize_utf8 (dfa) re_dfa_t *dfa; { - int node; + int node, i; for (node = 0; node < dfa->nodes_len; ++node) switch (dfa->nodes[node].type) @@ -999,6 +999,12 @@ optimize_utf8 (dfa) case OP_OPEN_SUBEXP: case OP_CLOSE_SUBEXP: break; + case SIMPLE_BRACKET: + /* Just double check. */ + for (i = 0x80 / UINT_BITS; i < BITSET_UINTS; ++i) + if (dfa->nodes[node].opr.sbcset[i]) + return; + break; default: return; } -- 2.7.4