diff options
author | M. Kristall <mkpdev@gmail.com> | 2009-10-19 07:09:55 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:16:56 +0000 |
commit | 4bede371a0f04d5edf3bd28f503ccf11cc9c6f47 (patch) | |
tree | d2d2dfa738432e3f13893902d5392903cbd13a13 /src/ui/ui_atoms.c | |
parent | be79439b479902f5b464511e95c4c5455071e8fa (diff) |
* Use binary searching instead of linear searching for many static arrays
Diffstat (limited to 'src/ui/ui_atoms.c')
-rw-r--r-- | src/ui/ui_atoms.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/ui/ui_atoms.c b/src/ui/ui_atoms.c index 9f0f3a9a..8f31225f 100644 --- a/src/ui/ui_atoms.c +++ b/src/ui/ui_atoms.c @@ -153,18 +153,18 @@ static void UI_MessageMode_f( void ) Menus_ActivateByName( "say" ); } -struct +struct uicmd { char *cmd; void ( *function )( void ); } commands[ ] = { - { "ui_load", UI_Load }, - { "ui_report", UI_Report }, - { "ui_cache", UI_Cache_f }, + { "closemenus", UI_CloseMenus_f }, + { "menu", UI_Menu_f }, { "messagemode", UI_MessageMode_f }, { "messagemode2", UI_MessageMode_f }, - { "menu", UI_Menu_f }, - { "closemenus", UI_CloseMenus_f } + { "ui_cache", UI_Cache_f }, + { "ui_load", UI_Load }, + { "ui_report", UI_Report } }; /* @@ -174,20 +174,17 @@ UI_ConsoleCommand */ qboolean UI_ConsoleCommand( int realTime ) { - char *cmd; - int i; + struct uicmd *cmd = bsearch( UI_Argv( 0 ), commands, + sizeof( commands ) / sizeof( commands[ 0 ] ), sizeof( commands[ 0 ] ), + cmdcmp ); uiInfo.uiDC.frameTime = realTime - uiInfo.uiDC.realTime; uiInfo.uiDC.realTime = realTime; - cmd = UI_Argv( 0 ); - for( i = 0; i < sizeof( commands ) / sizeof( commands[ 0 ] ); i++ ) + if( cmd ) { - if( Q_stricmp( commands[ i ].cmd, cmd ) == 0 ) - { - commands[ i ].function( ); - return qtrue; - } + cmd->function( ); + return qtrue; } return qfalse; |