This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Integrated hashtables, take 3
- To: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Subject: Re: Integrated hashtables, take 3
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- Date: Sun, 20 May 2001 17:18:31 +1000
- Cc: gcc-patches at gcc dot gnu dot org
- References: <20010519233318.A24362@daikokuya.demon.co.uk>
On 19-May-2001, Neil Booth <neil@daikokuya.demon.co.uk> wrote:
> --- c-lang.c 2001/03/20 02:57:27 1.49
> +++ c-lang.c 2001/05/19 22:04:53
> @@ -59,7 +59,10 @@ c_post_options ()
> static void
> c_init_options ()
> {
> - parse_in = cpp_create_reader (CLK_GNUC89);
> + /* Make identifier nodes long enough for the language-specific slots. */
> + set_identifier_size (sizeof (struct lang_identifier));
> +
> + parse_in = cpp_create_reader (ident_hash, CLK_GNUC89);
I think that should be done in c_init() rather than in c_init_options().
> --- objc-act.c 2001/05/16 06:22:15 1.82
> +++ objc-act.c 2001/05/19 22:07:51
> @@ -727,7 +727,10 @@ generate_struct_by_value_array ()
> static void
> objc_init_options ()
> {
> - parse_in = cpp_create_reader (CLK_OBJC);
> + /* Make identifier nodes long enough for the language-specific slots. */
> + set_identifier_size (sizeof (struct lang_identifier));
> +
> + parse_in = cpp_create_reader (ident_hash, CLK_OBJC);
> c_language = clk_objective_c;
> }
Likewise.
> Index: hashtable.c
...
> +static unsigned int
> +calc_hash (str, len)
> + const unsigned char *str;
> + unsigned int len;
> +{
> + unsigned int n = len;
> + unsigned int r = 0;
> +#define HASHSTEP(r, c) ((r) * 67 + (c - 113));
> +
> + while (n--)
> + r = HASHSTEP (r, *str++);
> +
> + return r + len;
> +#undef HASHSTEP
> +}
As a matter of style, I would recomment putting the macro
arguments in parentheses:
s/c - 113/(c) - 113/
> +/* Return the approximate positive square root of a number N. This is for
> + statistical reports, not code generation. */
> +double
> +approx_sqrt (x)
> + double x;
> +{
> + double s, d;
> +
> + if (x < 0)
> + abort ();
> + if (x == 0)
> + return 0;
> +
> + s = x;
> + do
> + {
> + d = (s * s - x) / (2 * s);
> + s -= d;
> + }
> + while (d > .0001);
> + return s;
> +}
I know you only moved this code around...
but what's the rationale for not just using sqrt()?
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.