tuse binary search for tags - webdump - [FORK] git://git.codemadness.org/webdump
 (HTM) git clone git://git.z3bra.org/webdump.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d51661848fc21d2657e3465cfda192a6df482c0e
 (DIR) parent db8f34a3ca6cfbde225ad4d723b3978e4f34578c
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Mon,  9 Dec 2019 18:46:40 +0100
       
       use binary search for tags
       
       Diffstat:
         M webdump.c                           |      26 ++++++++++++++++++--------
       
       1 file changed, 18 insertions(+), 8 deletions(-)
       ---
 (DIR) diff --git a/webdump.c b/webdump.c
       t@@ -71,7 +71,7 @@ enum DisplayType {
        };
        
        struct tag {
       -        char *name;
       +        const char *name;
                enum DisplayType displaytype;
                enum DisplayType parenttype; /* display type belonging to element */
                int autoclose;
       t@@ -567,11 +567,20 @@ xmldataentity(XMLParser *p, const char *data, size_t datalen)
                        xmldata(p, data, datalen);
        }
        
       +int
       +tagcmp(const void *v1, const void *v2)
       +{
       +        struct tag *t1 = (struct tag *)v1;
       +        struct tag *t2 = (struct tag *)v2;
       +
       +        return strcasecmp(t1->name, t2->name);
       +}
       +
        static void
        xmltagstart(XMLParser *x, const char *t, size_t tl)
        {
       +        struct tag find, *found;
                struct node *cur;
       -        int i;
        
                if (curnode >= MAX_DEPTH - 2)
                        errx(1, "max tag depth reached: %d\n", curnode);
       t@@ -585,12 +594,13 @@ xmltagstart(XMLParser *x, const char *t, size_t tl)
                src[0] = '\0'; /* src, href */
        
                /* match tag */
       -        for (i = 0; i < sizeof(tags) / sizeof(*tags); i++) {
       -                if (!strcasecmp(tags[i].name, t)) {
       -                        cur->nchildren = 0;
       -                        memcpy(&(cur->tag), &tags[i], sizeof(tags[i]));
       -                        break;
       -                }
       +        find.name = t;
       +        found = bsearch(&find, tags, sizeof(tags) / sizeof(*tags),
       +                sizeof(*tags), tagcmp);
       +        if (found) {
       +                cur->nchildren = 0;
       +                memcpy(&(cur->tag), found, sizeof(*found));
       +                return;
                }
        }