Browse Source

engine: common: base_cmd: alphabetically order inserts for faster lookups

pull/2/head
Alibek Omarov 2 years ago
parent
commit
8e45a43ad2
  1. 16
      engine/common/base_cmd.c

16
engine/common/base_cmd.c

@ -122,15 +122,23 @@ Add new typed base command to hashmap
*/ */
void BaseCmd_Insert( base_command_type_e type, base_command_t *basecmd, const char *name ) void BaseCmd_Insert( base_command_type_e type, base_command_t *basecmd, const char *name )
{ {
uint hash = COM_HashKey( name, HASH_SIZE ); base_command_hashmap_t *elem, *cur, *find;
base_command_hashmap_t *elem; uint hash = BaseCmd_HashKey( name );
elem = Z_Malloc( sizeof( base_command_hashmap_t ) ); elem = Z_Malloc( sizeof( base_command_hashmap_t ) );
elem->basecmd = basecmd; elem->basecmd = basecmd;
elem->type = type; elem->type = type;
elem->name = name; elem->name = name;
elem->next = hashed_cmds[hash];
hashed_cmds[hash] = elem; // link the variable in alphanumerical order
for( cur = NULL, find = hashed_cmds[hash];
find && Q_strcmp( find->name, elem->name ) < 0;
cur = find, find = find->next );
if( cur ) cur->next = elem;
else hashed_cmds[hash] = elem;
elem->next = find;
} }
/* /*

Loading…
Cancel
Save