1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

html: Use binary search in htmlEntityValueLookup

This commit is contained in:
Nick Wellnhofer
2024-03-26 14:10:58 +01:00
parent 23a81841d2
commit aa04838eab

View File

@@ -2011,6 +2011,14 @@ htmlEntityLookup(const xmlChar *name) {
return(NULL); return(NULL);
} }
static int
htmlCompareEntityDesc(const void *vkey, const void *vdesc) {
const unsigned *key = vkey;
const htmlEntityDesc *desc = vdesc;
return((int) *key - (int) desc->value);
}
/** /**
* htmlEntityValueLookup: * htmlEntityValueLookup:
* @value: the entity's unicode value * @value: the entity's unicode value
@@ -2023,17 +2031,14 @@ htmlEntityLookup(const xmlChar *name) {
*/ */
const htmlEntityDesc * const htmlEntityDesc *
htmlEntityValueLookup(unsigned int value) { htmlEntityValueLookup(unsigned int value) {
unsigned int i; const htmlEntityDesc *desc;
size_t nmemb;
for (i = 0;i < (sizeof(html40EntitiesTable)/ nmemb = sizeof(html40EntitiesTable) / sizeof(html40EntitiesTable[0]);
sizeof(html40EntitiesTable[0]));i++) { desc = bsearch(&value, html40EntitiesTable, nmemb, sizeof(htmlEntityDesc),
if (html40EntitiesTable[i].value >= value) { htmlCompareEntityDesc);
if (html40EntitiesTable[i].value > value)
break; return(desc);
return((htmlEntityDescPtr) &html40EntitiesTable[i]);
}
}
return(NULL);
} }
/** /**