bin/71367: regex multibyte support is really slow
Tim Robbins
tjr at freebsd.org
Sat Sep 4 04:40:25 PDT 2004
The following reply was made to PR bin/71367; it has been noted by GNATS.
From: Tim Robbins <tjr at freebsd.org>
To: "Simon L. Nielsen" <simon at FreeBSD.org>
Cc: freebsd-gnats-submit at FreeBSD.org, Kuang-che Wu <kcwu at csie.org>
Subject: Re: bin/71367: regex multibyte support is really slow
Date: Sat, 4 Sep 2004 21:36:16 +1000
On Sat, Sep 04, 2004 at 01:21:22PM +0200, Simon L. Nielsen wrote:
> On 2004.09.04 10:50:27 +0000, Tim Robbins wrote:
> > > >How-To-Repeat:
> > > $ cc -O -pipe re.c -o re
> > > $ time ./re
> > > 7.65 real 7.51 user 0.06 sys
>
> > I can't reproduce these results. I get:
>
> I can, more or less.. :
>
> [simon at zaphod:/tmp] cc -O -pipe re.c -o re
> [simon at zaphod:/tmp] /usr/bin/time ./re
> 3,85 real 3,54 user 0,12 sys
Could you please try this patch?
--- lib/libc/regex/regcomp.c.old Sat Sep 4 21:33:53 2004
+++ lib/libc/regex/regcomp.c Sat Sep 4 21:32:50 2004
@@ -1199,13 +1199,15 @@
cset *cs;
wint_t ch;
{
- wint_t *newwides;
+ wint_t nch, *newwides;
assert(ch >= 0);
if (ch < NC) {
cs->bmp[ch >> 3] |= 1 << (ch & 7);
if (cs->icase) {
- cs->bmp[towlower(ch) >> 3] |= 1 << (towlower(ch) & 7);
- cs->bmp[towupper(ch) >> 3] |= 1 << (towupper(ch) & 7);
+ if ((nch = towlower(ch)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
+ if ((nch = towupper(ch)) < NC)
+ cs->bmp[nch >> 3] |= 1 << (nch & 7);
}
} else {
newwides = realloc(cs->wides, (cs->nwides + 1) *
@@ -1258,14 +1260,9 @@
wint_t i;
wctype_t *newtypes;
- for (i = 0; i < NC; i++) {
+ for (i = 0; i < NC; i++)
if (iswctype(i, wct))
CHadd(p, cs, i);
- if (cs->icase && i != towlower(i))
- CHadd(p, cs, towlower(i));
- if (cs->icase && i != towupper(i))
- CHadd(p, cs, towupper(i));
- }
newtypes = realloc(cs->types, (cs->ntypes + 1) *
sizeof(*cs->types));
if (newtypes == NULL) {
More information about the freebsd-bugs
mailing list