Skip to content

Lazy hot path lookup for entities #1150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/entities.c
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,8 @@ static const entity entities[] =
{ NULL, VERS_UNKNOWN, 0 },
};

static entity* entity_lookup_by_initial[128];

/*
** Pure static implementation. Trades off lookup speed
** for faster setup time (well, none actually).
Expand All @@ -2094,12 +2096,16 @@ static const entity* entitiesLookup( ctmbstr s )
const entity *np = entities;
if (ch == 0)
return NULL;
while (np->name)
{

if (entity_lookup_by_initial[ch] == 0) {
while (np->name) {
if (ch == *np->name)
break; /* stop when first letter matches */
break; /* stop when first letter matches */
np++;
}
entity_lookup_by_initial[ch] = np;
}
np = entity_lookup_by_initial[ch];
while (np->name)
{
if (ch != *np->name)
Expand Down