diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-03-23 10:21:44 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-03-23 10:21:44 -0400 |
commit | 74f388a893add09ba6a1e35151e0d2600cd688cb (patch) | |
tree | 71060e420a389c715e7f0a18fd1e1667508163aa | |
parent | 9827b2bae1d3864dffb06b50e2f59af594154693 (diff) | |
download | bfs-74f388a893add09ba6a1e35151e0d2600cd688cb.tar.xz |
trie: Calculate representative indices branchlessly
-rw-r--r-- | src/trie.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -206,9 +206,10 @@ static struct trie_leaf *trie_representative(const struct trie *trie, const void if ((offset >> 1) < length) { unsigned char nibble = trie_key_nibble(key, offset); unsigned int bit = 1U << nibble; - if (node->bitmap & bit) { - index = count_ones(node->bitmap & (bit - 1)); - } + // bits = bitmap & bit ? bitmap & (bit - 1) : 0 + unsigned int mask = -!!(node->bitmap & bit); + unsigned int bits = node->bitmap & (bit - 1) & mask; + index = count_ones(bits); } ptr = node->children[index]; } |