[vlc-devel] commit: vlc_GetActionId: binary search ( Rémi Denis-Courmont )
git version control
git at videolan.org
Mon Dec 28 13:23:06 CET 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 28 11:38:35 2009 +0200| [5d90c3fa0c62e164c3aef5c5075b64f7455fa777] | committer: Rémi Denis-Courmont
vlc_GetActionId: binary search
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5d90c3fa0c62e164c3aef5c5075b64f7455fa777
---
src/misc/action.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/misc/action.c b/src/misc/action.c
index e5eb94f..d0be62f 100644
--- a/src/misc/action.c
+++ b/src/misc/action.c
@@ -26,6 +26,7 @@
#include <vlc_common.h>
#include "../libvlc.h"
#include <vlc_keys.h>
+#include <stdlib.h>
int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
vlc_value_t prevkey, vlc_value_t curkey, void *priv)
@@ -46,11 +47,18 @@ int vlc_key_to_action (vlc_object_t *libvlc, const char *varname,
return var_SetInteger (libvlc, "key-action", key->i_action);
}
+static int actcmp(const void *key, const void *ent)
+{
+ const struct action *act = ent;
+ return strcmp(key, act->name);
+}
+
vlc_key_t vlc_GetActionId(const char *name)
{
- for (size_t i = 0; i < libvlc_actions_count; i++)
- if (!strcmp(libvlc_actions[i].name, name))
- return libvlc_actions[i].value;
- return 0;
+ const struct action *act;
+
+ act = bsearch(name, libvlc_actions, libvlc_actions_count, sizeof(*act),
+ actcmp);
+ return (act != NULL) ? act->value : 0;
}
More information about the vlc-devel
mailing list