mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 12:52:46 +00:00
use the Hash_*Element functions for opcodes to avoid the silliness of trying
to use strings for numeric keys
This commit is contained in:
parent
3f79367865
commit
712aecb1a2
1 changed files with 16 additions and 15 deletions
|
@ -215,29 +215,28 @@ opcode_t pr_opcodes[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const char *
|
static unsigned long
|
||||||
opcode_get_key (void *_op, void *unused)
|
opcode_get_hash (void *op, void *unused)
|
||||||
{
|
{
|
||||||
static char rep[4];
|
return ((opcode_t *)op)->opcode;
|
||||||
char *r = rep;
|
}
|
||||||
opcode_t *op = (opcode_t *)_op;
|
|
||||||
|
|
||||||
*r++ = (op->opcode & 0x7f) + 2;
|
static int
|
||||||
*r++ = ((op->opcode >> 7) & 0x7f) + 2;
|
opcode_compare (void *_opa, void *_opb, void *unused)
|
||||||
*r++ = ((op->opcode >> 14) & 0x3) + 2;
|
{
|
||||||
*r = 0;
|
opcode_t *opa = (opcode_t *)_opa;
|
||||||
return rep;
|
opcode_t *opb = (opcode_t *)_opb;
|
||||||
|
|
||||||
|
return opa->opcode == opb->opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
opcode_t *
|
opcode_t *
|
||||||
PR_Opcode (short opcode)
|
PR_Opcode (short opcode)
|
||||||
{
|
{
|
||||||
char rep[100];
|
|
||||||
opcode_t op;
|
opcode_t op;
|
||||||
|
|
||||||
op.opcode = opcode;
|
op.opcode = opcode;
|
||||||
strcpy (rep, opcode_get_key (&op, 0));
|
return Hash_FindElement (opcode_table, &op);
|
||||||
return Hash_Find (opcode_table, rep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -245,11 +244,13 @@ PR_Opcode_Init (void)
|
||||||
{
|
{
|
||||||
opcode_t *op;
|
opcode_t *op;
|
||||||
|
|
||||||
opcode_table = Hash_NewTable (1021, opcode_get_key, 0, 0);
|
opcode_table = Hash_NewTable (1021, 0, 0, 0);
|
||||||
|
Hash_SetHashCompare (opcode_table, opcode_get_hash, opcode_compare);
|
||||||
|
|
||||||
for (op = pr_opcodes; op->name; op++) {
|
for (op = pr_opcodes; op->name; op++) {
|
||||||
Hash_Add (opcode_table, op);
|
Hash_AddElement (opcode_table, op);
|
||||||
}
|
}
|
||||||
|
Hash_Stats (opcode_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|
Loading…
Reference in a new issue