[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [BUG]
From: |
Shigio YAMAGUCHI |
Subject: |
Re: [BUG] |
Date: |
Sat, 14 Sep 2013 08:15:38 +0900 |
On Sat, 14 Sep 2013 01:22:12 +0900
Hideki IWAMOTO <address@hidden> wrote:
> Hi. Yamaguchi san.
>
> There are some problems in searching using the pattern
> which contains '^' at the head.
>
> ======== example 1 ========
> $ cat a.c
> vsprintf
> sprintf
> asprintf
> $ global -sx '^v?sprintf'
> vsprintf 1 a.c vsprintf
> $ global -sx '^(v)?sprintf'
> sprintf 2 a.c sprintf
> vsprintf 1 a.c vsprintf
> ===========================
>
> Although '^v?sprintf should be equivalent to '^(v)?sprintf',
> the former does not match 'sprintf'.
>
> I think that the following code in gtags_first() is broken
> and it should be removed.
>
> 617 const char *p;
> 618 /*
> 619 * If the pattern include '^' + some non regular
> expression
> 620 * characters like '^aaa[0-9]', we take prefix read
> method
> 621 * with the non regular expression part as the prefix.
> 622 */
> 623 if (!(flags & GTOP_IGNORECASE) && *pattern == '^' &&
> *(p = pattern + 1) && !isregexchar(*p)) {
> 624 int i = 0;
> 625
> 626 while (*p && !isregexchar(*p) && i < IDENTLEN)
> 627 prefix[i++] = *p++;
> 628 prefix[i] = '\0';
> 629 key = prefix;
> 630 dbflags |= DBOP_PREFIX;
> 631 } else {
>
>
> Reducing the length of the string copied to prefix[] by 1 byte
> does not solve the following problem.
>
> ======== example 2 ========
> $ cat b.c
> geta
> seta
> $ global -sx '^get|^set'
> get 1 b.c geta
> $ global -sx '(^get)|(^set)'
> get 1 b.c geta
> set 2 b.c seta
> ===========================
>
Hi iwamoto san,
You are right. It was a wrong optimization.
How about the following?
[This code replaces the 617-631]
/*
* If the pattern is '^' + <non regular expression> like '^aaa',
* we take prefix read method with the non regular expression part
* as a prefix.
*/
if (!(flags & GTOP_IGNORECASE) && *pattern == '^' && !isregex(pattern +
1)) {
key = pattern + 1;
dbflags |= DBOP_PREFIX;
} else {
This code rescues '^' + <non regular expression> like '^set' at least.
[removed]
$ /usr/bin/time global -xs '^set' > /tmp/out1
0.44 real 0.30 user 0.12 sys
[using this code]
$ /usr/bin/time global -xs '^set' > /tmp/out2
0.08 real 0.05 user 0.02 sys
$ diff /tmp/out1 /tmp/out2
$
(tested using FreeBSD kernel source)
This code works well in the following cases too:
$ global -sx ^v?sprintf
sprintf 2 a.c sprintf
vsprintf 1 a.c vsprintf
$ global -sx ^(v)?sprintf
sprintf 2 a.c sprintf
vsprintf 1 a.c vsprintf
$ global -sx ^get|^set
geta 1 b.c geta
seta 2 b.c seta
$ global -sx (^get)|(^set)
geta 1 b.c geta
seta 2 b.c seta
> --
> Hideki IWAMOTO <address@hidden>
--
Shigio YAMAGUCHI <address@hidden>
PGP fingerprint: D1CB 0B89 B346 4AB6 5663 C4B6 3CA5 BBB3 57BE DDA3
- [BUG], Hideki IWAMOTO, 2013/09/13
- Re: [BUG],
Shigio YAMAGUCHI <=