Re: [AD] Allegro 5 new config routines, alpha 1 |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
IMHO, casting (char*) to (unsigned short*) is asking for troubles.
Suggested changes are given below.
"Angelo Mottola" <a.mottola@xxxxxxxxxx> writes:
> static inline int hash_code(char *string)
> {
> int i;
> unsigned short *p, code =3D 0;
> =20
> if ((!string) || (*string =3D=3D '\0'))
> return 0;
> =20
> for (p =3D (unsigned short *)string, i =3D (strlen(string) + 1) >> 1; =
> i; i--, p++) {
int ch;
unsigned char p = (unsigned char*) string;
unsigned int code = 0;
while ((ch = *p++) != '\0')
code = ((code >> BZT) | ((code << (16 - BZT)) & 0xFFFF)) ^ ch;
I suggest 3 or 5 for BZT (and some better name for it).
> code ^=3D *p;
> code =3D (code >> 1) | ((code & 1) << 16);
^^ this must be 15
> }
> return (int)(code & (CONFIG_DIR_SIZE - 1));
> }
--
Michael Bukin