Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: Hilfinger@adacore.com, Tom Tromey <tromey@redhat.com>,
	       Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] Extend hashed symbol dictionaries to work with Ada
Date: Wed, 06 Oct 2010 23:59:00 -0000	[thread overview]
Message-ID: <AANLkTinak7-mHU=tvqUKnJwubvMHnwQmtp5uU+14QUVc@mail.gmail.com> (raw)
In-Reply-To: <201010050820.o958Kf42002588@syracuse.mckusick.com>

On Tue, Oct 5, 2010 at 1:20 AM, Paul Hilfinger
<hilfingr@syracuse.mckusick.com> wrote:
>
> This patch allows Ada to speed up symbol lookup by using the facilities
> in dictionary.[ch] for hashed lookups.  First, we generalize dictionary
> search to allow clients to specify any matching function compatible with
> the hashing function. Next, we modify the hashing algorithm so that symbols
> that wild-match a name hash to the same value.  Finally, we modify Ada
> symbol lookup to use these facilities.
>
> Because this patch touches on a hashing algorithm used by other
> languages, I took the precaution of doing a speed test on a list of
> about 12000 identifiers (repeatedly inserting all of them into a table
> and then doing a lookup on a million names at random, thus testing the
> speed of the hashing algorithm and how well it distributed names).
> There was actually a slight speedup, probably as a result of open-
> coding some of the tests in msymbol_hash_iw.  By design, the revised
> hashing algorithm produces the same results as the original on most
> "normal" C identifiers.
>
> We considered augmenting the dictionary interface still further by allowing
> different hashing algorithms for different dictionaries, based on the
> (supposed) language of the symbols in that dictionary.  While this produced
> better isolation of the changes to Ada programs, the additional flexibility
> also complicated the dictionary interface.  I'd prefer to keep things
> simple for now.
>
>[...]

Hi.  I wouldn't mind having a couple of comments added to this function:

>
> +static unsigned int
> +dict_hash (const char *string)
> +{
> +  unsigned int hash;
> +  int c;
> +
> +  if (*string == '_' && strncmp (string, "_ada_", 5) == 0)
> +    string += 5;
> +
> +  hash = 0;
> +  while (*string)
> +    {
> +      switch (*string)
> +       {
> +       case '$': case '.': case 'X': case '(':

Why is 'X' special cased?
[Actually, I'd have the comment explain all of these special cases.]

> +         return hash;
> +       case ' ':
> +         string += 1;
> +         break;
> +       case '_':
> +         if (string[1] == '_')
> +           {
> +             if (((c = string[2]) < 'a' || c > 'z') && c != 'O')

Why does this `if' exist?

> +               return hash;
> +             hash = 0;

Why do we restart calculating the hash here?

> +             string += 2;
> +             break;
> +           }
> +         /* FALL THROUGH */
> +       default:
> +         hash = hash * 67 + *string - 113;
> +         string += 1;
> +         break;
> +       }
> +    }
> +  return hash;
> +}
> +


  parent reply	other threads:[~2010-10-06 23:59 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-05  8:20 Paul Hilfinger
2010-10-06 22:43 ` Tom Tromey
2010-10-06 22:53   ` Tom Tromey
2010-10-07  3:31     ` Paul Hilfinger
2010-10-07  7:17     ` [commit] " Paul Hilfinger
2010-10-07  8:44     ` [commit] Correct dict_hash to our most recent version Paul Hilfinger, :
2010-10-08 22:59       ` Tom Tromey
2010-10-07  3:29   ` [RFA] Extend hashed symbol dictionaries to work with Ada Paul Hilfinger
2010-10-06 23:18 ` Joel Brobecker
2010-10-06 23:59 ` Doug Evans [this message]
2010-10-07  6:29   ` Paul Hilfinger

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='AANLkTinak7-mHU=tvqUKnJwubvMHnwQmtp5uU+14QUVc@mail.gmail.com' \
    --to=dje@google.com \
    --cc=Hilfinger@adacore.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@redhat.com \
    /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: link
Be 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