[vlc-devel] commit: ConfigKeyToString: binary search ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed Oct 7 21:43:36 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct  7 22:24:45 2009 +0300| [b72ccbc55b251bcdf1da8a359a773fad19dd82de] | committer: Rémi Denis-Courmont 

ConfigKeyToString: binary search

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b72ccbc55b251bcdf1da8a359a773fad19dd82de
---

 src/config/keys.c |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/config/keys.c b/src/config/keys.c
index 0fd50cd..ef251af 100644
--- a/src/config/keys.c
+++ b/src/config/keys.c
@@ -175,8 +175,7 @@ char *KeyToString (uint_fast32_t sym)
 {
     key_descriptor_t *d;
 
-    d = (key_descriptor_t *)
-        bsearch ((void *)(uintptr_t)sym, vlc_keys, vlc_num_keys,
+    d = bsearch ((void *)(uintptr_t)sym, vlc_keys, vlc_num_keys,
                  sizeof (vlc_keys[0]), cmpkey);
     return d ? strdup (d->psz_key_string) : NULL;
 }
@@ -238,14 +237,16 @@ char *ConfigKeyToString (uint_fast32_t i_key)
                            vlc_modifiers[i].psz_key_string);
         }
     }
-    for (size_t i = 0; i < vlc_num_keys; i++)
-    {
-        if ((i_key & ~KEY_MODIFIER) == vlc_keys[i].i_key_code)
-        {
-            p += snprintf (p, psz_end - p, "%s",
-                           vlc_keys[i].psz_key_string);
-            break;
-        }
-    }
+
+    key_descriptor_t *d;
+
+    i_key &= ~KEY_MODIFIER;
+    d = bsearch ((void *)(uintptr_t)i_key, vlc_keys, vlc_num_keys,
+                 sizeof (vlc_keys[0]), cmpkey);
+    if (d)
+        p += snprintf (p, psz_end - p, "%s", d->psz_key_string);
+    else
+        return NULL;
+
     return psz_key;
 }




More information about the vlc-devel mailing list