public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "mscfd at gmx dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/98426] find_symbol in module.c traverses O(N) part of a search tree Date: Tue, 29 Dec 2020 11:15:23 +0000 [thread overview] Message-ID: <bug-98426-4-DnFqOxYWXq@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-98426-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98426 --- Comment #3 from martin <mscfd at gmx dot net> --- Sorry for the noise, but as this gives big reductions in compilation time it is quite important to me (and probably other big module based projects). I just realised that I mixed up gfc_symtree->name and gfc_symtree->n.sym->name. The reason why find_symbol traverses the whole tree in the worst case is that it is ordered by gfc_symtree->name but it looks for gfc_symtree->n.sym->name. So far I got the impression that either gfc_symtree->name is a unique name ("@xxx") or equal to gfc_symtree->n.sym->name (if n.sym!=NULL). In this case, the following patch should do the trick and traverse only log(N) of the tree: diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 4c6ff22d5c1..8dc59e25d46 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -4659,10 +4659,20 @@ find_symbol (gfc_symtree *st, const char *name, return st; } + c = strcmp (name, st->name); + if (c < 0) + retval = find_symbol (st->left, name, module, generic); + else if (c > 0) + retval = find_symbol (st->right, name, module, generic); + else + retval = NULL; + +/* original traverse retval = find_symbol (st->left, name, module, generic); if (retval == NULL) retval = find_symbol (st->right, name, module, generic); +*/ return retval; }
next prev parent reply other threads:[~2020-12-29 11:15 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-12-23 10:42 [Bug fortran/98426] New: " mscfd at gmx dot net 2020-12-28 10:29 ` [Bug fortran/98426] " mscfd at gmx dot net 2020-12-28 10:36 ` mscfd at gmx dot net 2020-12-29 11:15 ` mscfd at gmx dot net [this message] 2021-10-29 18:36 ` aldot at gcc dot gnu.org 2024-04-23 20:40 ` matthew.thompson at nasa dot gov 2024-04-23 23:26 ` jvdelisle at gcc dot gnu.org 2024-04-24 2:59 ` jvdelisle at gcc dot gnu.org 2024-04-24 3:05 ` jvdelisle at gcc dot gnu.org 2024-04-25 11:20 ` matthew.thompson at nasa dot gov 2024-04-25 16:38 ` jvdelisle at gcc dot gnu.org 2024-04-26 3:12 ` jvdelisle at gcc dot gnu.org 2024-04-26 12:43 ` matthew.thompson at nasa dot gov 2024-04-26 15:53 ` matthew.thompson at nasa dot gov 2024-04-26 15:54 ` matthew.thompson at nasa dot gov 2024-04-27 2:34 ` jvdelisle at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-98426-4-DnFqOxYWXq@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).