bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash minor code cleanup for 'long' in hashlib.c


From: Paul Eggert
Subject: bash minor code cleanup for 'long' in hashlib.c
Date: Thu, 12 Apr 2001 14:48:12 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' 
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8' 
-DCONF_VENDOR='sun' -DSHELL  -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib 
-I/opt/reb/include -g -O2 -Wall
uname output: SunOS shade.twinsun.com 5.8 Generic_108528-06 sun4u sparc 
SUNW,Ultra-1
Machine Type: sparc-sun-solaris2.8

Bash Version: 2.05
Patch Level: 0
Release Status: release

Description:
        This patch doesn't fix any bugs; it's just a minor coding cleanup.

        hash_string uses 'unsigned long' and discards information,
        where plain 'unsigned' would work, would be simpler, and would
        discard less info.

        Perhaps the code is written the way it is to avoid an old compiler
        bug?  In that case, perhaps it should be commented that way.

Repeat-By:

Fix:
2001-04-12  Paul Eggert  <address@hidden>

        * hashlib.c (ALL_ONES, BITS): Remove.
        (hash_string): Don't discard information above the bottom 31 bits.

===================================================================
RCS file: RCS/hashlib.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- hashlib.c   2001/02/14 21:58:55     2.5
+++ hashlib.c   2001/04/12 21:44:05     2.5.0.1
@@ -68,10 +68,7 @@ make_hash_table (buckets)
    for STRING.  TABLE is a pointer to a HASH_TABLE. */
 
 /* A possibly better distribution may be obtained by initializing i to
-   ~0UL and using i = (i * 31) + *string++ as the step */
-
-#define ALL_ONES (~((unsigned long) 0))
-#define BITS(h, n) ((unsigned long)(h) & ~(ALL_ONES << (n)))
+   -1 and using i = (i * 31) + *string++ as the step */
 
 int
 hash_string (string, table)
@@ -83,7 +80,8 @@ hash_string (string, table)
   while (*string)
     i = (i << 2) + *string++;
 
-  return (BITS (i, 31) % table->nbuckets);
+  /* unsigned%int uses unsigned division, so the result can't be negative.  */
+  return (i % table->nbuckets);
 }
 
 /* Return a pointer to the hashed item, or NULL if the item



reply via email to

[Prev in Thread] Current Thread [Next in Thread]