Skip to content

Commit

Permalink
kernel: optimize traversal hash table
Browse files Browse the repository at this point in the history
At least my compiler over here did not hoist the load for
traversal->hashCapacity out of the loop at -O2.
  • Loading branch information
fingolfin committed Oct 15, 2019
1 parent 75671b8 commit 4c9d131
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/hpc/traverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static int SeenDuringTraversal(TraversalState * traversal, Obj obj)
TraversalRehash(traversal);
hash = FibHash((UInt)obj, traversal->hashBits);
hashTable = ADDR_OBJ(traversal->hashTable) + 1;
const UInt mask = traversal->hashCapacity - 1;
for (;;) {
if (hashTable[hash] == NULL) {
hashTable[hash] = obj;
Expand All @@ -108,7 +109,7 @@ static int SeenDuringTraversal(TraversalState * traversal, Obj obj)
}
if (hashTable[hash] == obj)
return 0;
hash = (hash + 1) & (traversal->hashCapacity - 1);
hash = (hash + 1) & mask;
}
}

Expand All @@ -120,12 +121,13 @@ static UInt FindTraversedObj(TraversalState * traversal, Obj obj)
return 0;
hash = FibHash((UInt)obj, traversal->hashBits);
hashTable = ADDR_OBJ(traversal->hashTable) + 1;
const UInt mask = traversal->hashCapacity - 1;
for (;;) {
if (hashTable[hash] == obj)
return (int)hash + 1;
if (hashTable[hash] == NULL)
return 0;
hash = (hash + 1) & (traversal->hashCapacity - 1);
hash = (hash + 1) & mask;
}
}

Expand Down

0 comments on commit 4c9d131

Please sign in to comment.