Skip to content

Commit

Permalink
[std.regex] Optimize reads from hash table
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryOlshansky committed Oct 11, 2016
1 parent 71dc211 commit d745fb8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion std/regex/internal/bitnfa.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pure:

uint opIndex()(uint key) const
{
auto p = locate(key, table);
auto p = locateExisting(key, table);
assert(p.occupied);
return p.value;
}
Expand Down Expand Up @@ -95,6 +95,19 @@ private:
Node[] table;
size_t items;

static N* locateExisting(N)(uint key, N[] table)
{
size_t slot = hashOf(key) & (table.length-1);
key |= 0x8000_0000;
while (table[slot].key_ != key)
{
slot += 1;
if (slot == table.length)
slot = 0;
}
return table.ptr + slot;
}

static N* locate(N)(uint key, N[] table)
{
size_t slot = hashOf(key) & (table.length-1);
Expand Down

0 comments on commit d745fb8

Please sign in to comment.