From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22045 invoked by alias); 4 Oct 2010 06:47:23 -0000 Received: (qmail 22035 invoked by uid 22791); 4 Oct 2010 06:47:22 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,SPF_SOFTFAIL,TW_BJ,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: sourceware.org Received: from syracuse.mckusick.com (HELO syracuse.mckusick.com) (64.81.247.46) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Oct 2010 06:47:16 +0000 Received: from syracuse.mckusick.com (localhost [127.0.0.1]) by syracuse.mckusick.com (8.14.3/8.14.3/Debian-9.1ubuntu1) with ESMTP id o946lEFj017082 for ; Sun, 3 Oct 2010 23:47:14 -0700 Received: (from hilfingr@localhost) by syracuse.mckusick.com (8.14.3/8.14.3/Submit) id o946lDbQ017080 for gdb-patches@sourceware.org; Sun, 3 Oct 2010 23:47:13 -0700 Subject: [commit] Replace wild_match with faster version and modify its interface. From: Paul Hilfinger Reply-To: Hilfinger@adacore.com To: gdb-patches@sourceware.org In-Reply-To: <201010010630.o916Uf5W001809@syracuse.mckusick.com> References: <201010010630.o916Uf5W001809@syracuse.mckusick.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Date: Mon, 04 Oct 2010 06:47:00 -0000 Message-ID: <1286174832.16964.5.camel@syracuse.mckusick.com> Mime-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00026.txt.bz2 I have committed the patch below, as previously indicated. This new version of wild_match is comparable in speed to strcmp_iw, and has the same signature and same return value for equal names. gdb/ChangeLog: * ada-lang.c (wild_match): Reimplement. Change API to eliminate unused length argument, reverse arguments and make 0 the 'true' return value. (advance_wild_match): New auxiliary function for wild_match to=20 improve readability. (ada_match_name, ada_add_block_symbols): Use new API for wild_match. * psymtab.c (ada_lookup_partial_symbol, map_ada_symtabs): Use new API for wild_match. * symfile.h (map_ada_symtabs): Modify declaration to use new API for wild_match. * dwarf2read.c (dw2_map_ada_symtabs): Ditto. --- gdb/ada-lang.c | 89 +++++++++++++++++++++++++++++++++++++++++------------ gdb/dwarf2read.c | 2 +- gdb/psymtab.c | 6 ++-- gdb/symfile.h | 2 +- 4 files changed, 74 insertions(+), 25 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 3eaf649..bb14c39 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -200,7 +200,9 @@ static int equiv_types (struct type *, struct type *); =20 static int is_name_suffix (const char *); =20 -static int wild_match (const char *, int, const char *); +static int advance_wild_match (const char **, const char *, int); + +static int wild_match (const char *, const char *); =20 static struct value *ada_coerce_ref (struct value *); =20 @@ -1260,7 +1262,7 @@ ada_match_name (const char *sym_name, const char *name, int wild) if (sym_name =3D=3D NULL || name =3D=3D NULL) return 0; else if (wild) - return wild_match (name, strlen (name), sym_name); + return wild_match (sym_name, name) =3D=3D 0; else { int len_name =3D strlen (name); @@ -4994,30 +4996,77 @@ is_valid_name_for_wild_match (const char *name0) return 1; } =20 -/* True if NAME represents a name of the form A1.A2....An, n>=3D1 and - PATN[0..PATN_LEN-1] =3D Ak.Ak+1.....An for some k >=3D 1. Ignores - informational suffixes of NAME (i.e., for which is_name_suffix is - true). */ +/* Advance *NAMEP to next occurrence of TARGET0 in the string NAME0 + that could start a simple name. Assumes that *NAMEP points into + the string beginning at NAME0. */ =20 static int -wild_match (const char *patn0, int patn_len, const char *name0) +advance_wild_match (const char **namep, const char *name0, int target0) { - char* match; - const char* start; + const char *name =3D *namep; =20 - start =3D name0; while (1) { - match =3D strstr (start, patn0); - if (match =3D=3D NULL) + int t0, t1, t2; + + t0 =3D *name; + if (t0 =3D=3D '_') + { + t1 =3D name[1]; + if ((t1 >=3D 'a' && t1 <=3D 'z') || (t1 >=3D '0' && t1 <=3D '9')) + { + name +=3D 1; + if (name =3D=3D name0 + 5 && strncmp (name0, "_ada", 4) =3D=3D 0) + break; + else + name +=3D 1; + } + else if (t1 =3D=3D '_' && + (((t2 =3D name[2]) >=3D 'a' && t2 <=3D 'z') || t2 =3D=3D target0)) + { + name +=3D 2; + break; + } + else + return 0; + } + else if ((t0 >=3D 'a' && t0 <=3D 'z') || (t0 >=3D '0' && t0 <=3D '9'= )) + name +=3D 1; + else return 0; - if ((match =3D=3D name0=20 - || match[-1] =3D=3D '.'=20 - || (match > name0 + 1 && match[-1] =3D=3D '_' && match[-2] =3D=3D '_') - || (match =3D=3D name0 + 5 && strncmp ("_ada_", name0, 5) =3D=3D 0)) - && is_name_suffix (match + patn_len)) - return (match =3D=3D name0 || is_valid_name_for_wild_match (name0)); - start =3D match + 1; + } + + *namep =3D name; + return 1; +} + +/* Return 0 iff NAME encodes a name of the form prefix.PATN. Ignores any + informational suffixes of NAME (i.e., for which is_name_suffix is + true). Assumes that PATN is a lower-cased Ada simple name. */ + +static int +wild_match (const char *name, const char *patn) +{ + const char *p, *n; + const char *name0 =3D name; + + while (1) + { + const char *match =3D name; + + if (*name =3D=3D *patn) + { + for (name +=3D 1, p =3D patn + 1; *p !=3D '\0'; name +=3D 1, p +=3D 1) + if (*p !=3D *name) + break; + if (*p =3D=3D '\0' && is_name_suffix (name)) + return match !=3D name0 && !is_valid_name_for_wild_match (name0); + + if (name[-1] =3D=3D '_') + name -=3D 1; + } + if (!advance_wild_match (&name, name0, *patn)) + return 1; } } =20 @@ -5051,7 +5100,7 @@ ada_add_block_symbols (struct obstack *obstackp, { if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), SYMBOL_DOMAIN (sym), domain) - && wild_match (name, name_len, SYMBOL_LINKAGE_NAME (sym))) + && wild_match (SYMBOL_LINKAGE_NAME (sym), name) =3D=3D 0) { if (SYMBOL_CLASS (sym) =3D=3D LOC_UNRESOLVED) continue; diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 743ba89..b313873 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -2359,7 +2359,7 @@ dw2_find_symbol_file (struct objfile *objfile, const char *name) =20 static void dw2_map_ada_symtabs (struct objfile *objfile, - int (*wild_match) (const char *, int, const char *), + int (*wild_match) (const char *, const char *), int (*is_name_suffix) (const char *), void (*callback) (struct objfile *, struct symtab *, void *), diff --git a/gdb/psymtab.c b/gdb/psymtab.c index aa6dc17..d882900 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -974,7 +974,7 @@ find_symbol_file_from_partial (struct objfile *objfile, const char *name) static struct partial_symbol * ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name, int global, domain_enum namespace, int wild, - int (*wild_match) (const char *, int, const char *), + int (*wild_match) (const char *, const char *), int (*is_name_suffix) (const char *)) { struct partial_symbol **start; @@ -999,7 +999,7 @@ ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name, =20 if (symbol_matches_domain (SYMBOL_LANGUAGE (psym), SYMBOL_DOMAIN (psym), namespace) - && (*wild_match) (name, name_len, SYMBOL_LINKAGE_NAME (psym))) + && (*wild_match) (SYMBOL_LINKAGE_NAME (psym), name) =3D=3D 0) return psym; } return NULL; @@ -1112,7 +1112,7 @@ ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name, =20 static void map_ada_symtabs (struct objfile *objfile, - int (*wild_match) (const char *, int, const char *), + int (*wild_match) (const char *, const char *), int (*is_name_suffix) (const char *), void (*callback) (struct objfile *, struct symtab *, void *), const char *name, int global, domain_enum namespace, int wild, diff --git a/gdb/symfile.h b/gdb/symfile.h index afa92cd..e48cfdd 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -220,7 +220,7 @@ struct quick_symbol_functions This function is completely ad hoc and new implementations should refer to the psymtab implementation to see what to do. */ void (*map_ada_symtabs) (struct objfile *objfile, - int (*wild_match) (const char *, int, const char *), + int (*wild_match) (const char *, const char *), int (*is_name_suffix) (const char *), void (*callback) (struct objfile *, struct symtab *, void *), --=20 1.7.0.4