Commit 35d24473 authored by Geoff Simmons's avatar Geoff Simmons

Speed up the exact match operation.

Only call strcmp() once, when a node is reached that must be either a
hit or a miss.
parent da885ca1
......@@ -236,13 +236,16 @@ PT_Lookup(const struct pt_y * const restrict root,
char * const restrict * const restrict strings,
const char * const restrict subject)
{
const struct pt_y *y = root;
size_t len;
AN(strings);
AN(subject);
if (root == NULL)
return UINT_MAX;
len = strlen(subject);
for (const struct pt_y *y = root; y != NULL;) {
for (;;) {
unsigned char b;
size_t l;
......@@ -250,13 +253,17 @@ PT_Lookup(const struct pt_y * const restrict root,
l = y->off + y->len;
if (l > len)
return UINT_MAX;
if (l == len && strcmp(subject, strings[y->idx]) == 0)
return y->idx;
if (l == len && strings[y->idx][l] == '\0')
break;
b = (y->bitmask & subject[l]) != 0;
assert(b < 2);
if (y->leaf[b] == NULL)
return UINT_MAX;
y = y->leaf[b];
}
if (strcmp(subject, strings[y->idx]) == 0)
return y->idx;
return (UINT_MAX);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment