#include "quakedef.h"
cvar_t *cvar_vars = NULL;
+cvar_t *cvar_hashtable[65536];
char *cvar_null_string = "";
/*
*/
cvar_t *Cvar_FindVar (const char *var_name)
{
+ int hashindex;
cvar_t *var;
- for (var = cvar_vars;var;var = var->next)
+ // use hash lookup to minimize search time
+ hashindex = CRC_Block((const unsigned char *)var_name, strlen(var_name));
+ for (var = cvar_hashtable[hashindex];var;var = var->nextonhashchain)
if (!strcasecmp (var_name, var->name))
return var;
*/
void Cvar_RegisterVariable (cvar_t *variable)
{
+ int hashindex;
cvar_t *current, *next, *cvar;
char *oldstr;
cvar_vars = variable;
}
variable->next = next;
+
+ // link to head of list in this hash table index
+ hashindex = CRC_Block((const unsigned char *)variable->name, strlen(variable->name));
+ variable->nextonhashchain = cvar_hashtable[hashindex];
+ cvar_hashtable[hashindex] = variable;
}
/*
*/
cvar_t *Cvar_Get (const char *name, const char *value, int flags)
{
- cvar_t *cvar;
+ int hashindex;
+ cvar_t *current, *next, *cvar;
if (developer.integer)
Con_Printf("Cvar_Get(\"%s\", \"%s\", %i);\n", name, value, flags);
cvar->description = "custom cvar";
// link the variable in
- cvar->next = cvar_vars;
- cvar_vars = cvar;
+// alphanumerical order
+ for( current = NULL, next = cvar_vars ; next && strcmp( next->name, cvar->name ) < 0 ; current = next, next = next->next )
+ ;
+ if( current )
+ current->next = cvar;
+ else
+ cvar_vars = cvar;
+ cvar->next = next;
+
+ // link to head of list in this hash table index
+ hashindex = CRC_Block((const unsigned char *)cvar->name, strlen(cvar->name));
+ cvar->nextonhashchain = cvar_hashtable[hashindex];
+ cvar_hashtable[hashindex] = cvar;
+
return cvar;
}