tint/utils: Optimise HashmapBase::Scan()

Avoid an integer modulo for each scan iteration.

Change-Id: Ie80af4620b39769db622b4ab175b5639cf9ade8e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108260
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-11-03 11:44:15 +00:00 committed by Dawn LUCI CQ
parent 6e3f9fa53d
commit aa4b64f4c8
1 changed files with 9 additions and 3 deletions

View File

@ -453,12 +453,18 @@ class HashmapBase {
/// * must return Action::kStop within one whole cycle of the slots. /// * must return Action::kStop within one whole cycle of the slots.
template <typename F> template <typename F>
void Scan(size_t start, F&& f) const { void Scan(size_t start, F&& f) const {
size_t index = start; size_t distance = 0;
for (size_t distance = 0; distance < slots_.Length(); distance++) { for (size_t index = start; index < slots_.Length(); index++) {
if (f(distance, index) == Action::kStop) { if (f(distance, index) == Action::kStop) {
return; return;
} }
index = Wrap(index + 1); distance++;
}
for (size_t index = 0; index < start; index++) {
if (f(distance, index) == Action::kStop) {
return;
}
distance++;
} }
tint::diag::List diags; tint::diag::List diags;
TINT_ICE(Utils, diags) << "HashmapBase::Scan() looped entire map without finding a slot"; TINT_ICE(Utils, diags) << "HashmapBase::Scan() looped entire map without finding a slot";