1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-20 18:50:08 +03:00

Speed up htmlTagLookup

Switch to binary search. This is the first time bsearch is used in the
libxml2 code base. But it's a standard library function since C89 and
should be portable.
This commit is contained in:
Nick Wellnhofer 2021-03-04 17:44:45 +01:00
parent ad101bb5b5
commit b25acce858

View File

@ -1269,6 +1269,14 @@ htmlInitAutoClose(void) {
htmlStartCloseIndexinitialized = 1; htmlStartCloseIndexinitialized = 1;
} }
static int
htmlCompareTags(const void *key, const void *member) {
const char *tag = (const char *) key;
const htmlElemDesc *desc = (const htmlElemDesc *) member;
return(strcmp(tag, desc->name));
}
/** /**
* htmlTagLookup: * htmlTagLookup:
* @tag: The tag name in lowercase * @tag: The tag name in lowercase
@ -1279,14 +1287,12 @@ htmlInitAutoClose(void) {
*/ */
const htmlElemDesc * const htmlElemDesc *
htmlTagLookup(const xmlChar *tag) { htmlTagLookup(const xmlChar *tag) {
unsigned int i; if (tag == NULL)
return(NULL);
for (i = 0; i < (sizeof(html40ElementTable) / return((const htmlElemDesc *) bsearch(tag, html40ElementTable,
sizeof(html40ElementTable[0]));i++) { sizeof(html40ElementTable) / sizeof(htmlElemDesc),
if (!xmlStrcasecmp(tag, BAD_CAST html40ElementTable[i].name)) sizeof(htmlElemDesc), htmlCompareTags));
return((htmlElemDescPtr) &html40ElementTable[i]);
}
return(NULL);
} }
/** /**