Skip to content

Commit

Permalink
Try a full loop in LoopItemsPropertiesExactlyTypeStrictHash's fallback
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Jan 17, 2025
1 parent fa5e0a0 commit dbeed0a
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/evaluator/dispatch.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2265,33 +2265,34 @@ 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;
}

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);
}
Expand Down

0 comments on commit dbeed0a

Please sign in to comment.