Gabriel Ivăncescu : mshtml: Use binary search when looking up events by name.

Alexandre Julliard julliard at winehq.org
Wed May 25 16:51:47 CDT 2022


Module: wine
Branch: master
Commit: 5eec1429fd8228af08b8f155b837a9a021b38d7c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5eec1429fd8228af08b8f155b837a9a021b38d7c

Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date:   Wed May 25 19:13:14 2022 +0300

mshtml: Use binary search when looking up events by name.

Since they're already sorted (except for DOMContentLoaded because of case
sensitivity).

Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/htmlevent.c | 27 ++++++++++++++++++---------
 dlls/mshtml/htmlevent.h |  2 +-
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/dlls/mshtml/htmlevent.c b/dlls/mshtml/htmlevent.c
index fe3433692f3..f28dd639ff6 100644
--- a/dlls/mshtml/htmlevent.c
+++ b/dlls/mshtml/htmlevent.c
@@ -105,7 +105,10 @@ typedef struct {
 #define EVENT_MOUSE_TO_RELATED   0x0100
 #define EVENT_MOUSE_FROM_RELATED 0x0200
 
+/* Keep these sorted case sensitively */
 static const event_info_t event_info[] = {
+    {L"DOMContentLoaded",  EVENT_TYPE_EVENT,     0,
+        EVENT_DEFAULTLISTENER | EVENT_BUBBLES | EVENT_CANCELABLE},
     {L"abort",             EVENT_TYPE_EVENT,     DISPID_EVMETH_ONABORT,
         EVENT_BIND_TO_TARGET},
     {L"animationend",      EVENT_TYPE_EVENT,     DISPID_EVPROP_ONANIMATIONEND,
@@ -128,8 +131,6 @@ static const event_info_t event_info[] = {
         EVENT_FIXME | EVENT_BUBBLES},
     {L"dblclick",          EVENT_TYPE_MOUSE,     DISPID_EVMETH_ONDBLCLICK,
         EVENT_DEFAULTLISTENER | EVENT_BUBBLES | EVENT_CANCELABLE},
-    {L"DOMContentLoaded",  EVENT_TYPE_EVENT,     0,
-        EVENT_DEFAULTLISTENER | EVENT_BUBBLES | EVENT_CANCELABLE},
     {L"drag",              EVENT_TYPE_DRAG,      DISPID_EVMETH_ONDRAG,
         EVENT_FIXME | EVENT_BUBBLES | EVENT_CANCELABLE},
     {L"dragstart",         EVENT_TYPE_DRAG,      DISPID_EVMETH_ONDRAGSTART,
@@ -192,11 +193,15 @@ C_ASSERT(ARRAY_SIZE(event_info) == EVENTID_LAST);
 
 static eventid_t str_to_eid(const WCHAR *str)
 {
-    int i;
+    unsigned i, a = 0, b = ARRAY_SIZE(event_info);
+    int c;
 
-    for(i=0; i < ARRAY_SIZE(event_info); i++) {
-        if(!wcscmp(event_info[i].name, str))
+    while(a < b) {
+        i = (a + b) / 2;
+        if(!(c = wcscmp(event_info[i].name, str)))
             return i;
+        if(c > 0) b = i;
+        else      a = i + 1;
     }
 
     return EVENTID_LAST;
@@ -204,14 +209,18 @@ static eventid_t str_to_eid(const WCHAR *str)
 
 static eventid_t attr_to_eid(const WCHAR *str)
 {
-    int i;
+    unsigned i, a = 0, b = ARRAY_SIZE(event_info);
+    int c;
 
     if((str[0] != 'o' && str[0] != 'O') || (str[1] != 'n' && str[1] != 'N'))
         return EVENTID_LAST;
 
-    for(i=0; i < ARRAY_SIZE(event_info); i++) {
-        if(!wcscmp(event_info[i].name, str+2) && event_info[i].dispid)
-            return i;
+    while(a < b) {
+        i = (a + b) / 2;
+        if(!(c = wcscmp(event_info[i].name, str+2)))
+            return event_info[i].dispid ? i : EVENTID_LAST;
+        if(c > 0) b = i;
+        else      a = i + 1;
     }
 
     return EVENTID_LAST;
diff --git a/dlls/mshtml/htmlevent.h b/dlls/mshtml/htmlevent.h
index 7f62bd69a7f..5d534512739 100644
--- a/dlls/mshtml/htmlevent.h
+++ b/dlls/mshtml/htmlevent.h
@@ -17,6 +17,7 @@
  */
 
 typedef enum {
+    EVENTID_DOMCONTENTLOADED,
     EVENTID_ABORT,
     EVENTID_ANIMATIONEND,
     EVENTID_ANIMATIONSTART,
@@ -28,7 +29,6 @@ typedef enum {
     EVENTID_CONTEXTMENU,
     EVENTID_DATAAVAILABLE,
     EVENTID_DBLCLICK,
-    EVENTID_DOMCONTENTLOADED,
     EVENTID_DRAG,
     EVENTID_DRAGSTART,
     EVENTID_ERROR,




More information about the wine-cvs mailing list