From dbeed0a240c159d40c1591c6b842ae0c524f8f83 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 17 Jan 2025 15:59:42 -0400 Subject: [PATCH] Try a full loop in `LoopItemsPropertiesExactlyTypeStrictHash`'s fallback Signed-off-by: Juan Cruz Viotti --- src/evaluator/dispatch.inc.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/evaluator/dispatch.inc.h b/src/evaluator/dispatch.inc.h index 3179d261..36e61bd5 100644 --- a/src/evaluator/dispatch.inc.h +++ b/src/evaluator/dispatch.inc.h @@ -2265,17 +2265,19 @@ INSTRUCTION_HANDLER(LoopItemsPropertiesExactlyTypeStrictHash) { EVALUATE_END(LoopItemsPropertiesExactlyTypeStrictHash); } - // The idea is to first assume the object property ordering and the - // hashes collection aligns. If they don't we do a full comparison - // from where we left of. - - std::size_t index{0}; for (const auto &entry : object) { if (entry.second.type() != value.first) { result = false; EVALUATE_END(LoopItemsPropertiesExactlyTypeStrictHash); } + } + // The idea is to first assume the object property ordering and the + // hashes collection aligns. If they don't we do a full comparison + // from where we left of. + + std::size_t index{0}; + for (const auto &entry : object) { if (entry.hash != value.second[index]) { break; } @@ -2283,15 +2285,14 @@ INSTRUCTION_HANDLER(LoopItemsPropertiesExactlyTypeStrictHash) { index += 1; } - if (index < size) { - auto iterator = object.cbegin(); - // Continue where we left - std::advance(iterator, index); - for (; iterator != object.cend(); ++iterator) { - if (std::none_of(value.second.cbegin(), value.second.cend(), - [&iterator](const auto hash) { - return hash == iterator->hash; - })) { + if (index != size) { + for (const auto &entry : object) { + // TODO: Sort value.second by hashes to do a binary search? + // Search in reverse, as we have better changes of finding + // a match given that if we are here, sequential search + // from start to finish failed + if (std::find(value.second.crbegin(), value.second.crend(), + entry.hash) == value.second.crend()) { result = false; EVALUATE_END(LoopItemsPropertiesExactlyTypeStrictHash); }