Skip to content

Commit

Permalink
Use object ptr as key for expression cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Anilm3 committed Oct 8, 2023
1 parent 2669a97 commit eae2c65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ eval_result expression::evaluator::eval_condition(
}

if (cache.targets.size() != cond.targets.size()) {
cache.targets.assign(cond.targets.size(), false);
cache.targets.assign(cond.targets.size(), nullptr);
}

for (unsigned i = 0; i < cond.targets.size(); ++i) {
Expand All @@ -138,18 +138,14 @@ eval_result expression::evaluator::eval_condition(
}

const auto &target = cond.targets[i];
if (cache.targets[i] && !store.is_new_target(target.root)) {
continue;
}

auto [object, attr] = store.get_target(target.root);
if (object == nullptr) {
if (object == nullptr || object == cache.targets[i]) {
continue;
}

bool ephemeral = (attr == object_store::attribute::ephemeral);
if (!ephemeral) {
cache.targets[i] = true;
cache.targets[i] = object;
}

std::optional<event::match> optional_match;
Expand Down
3 changes: 1 addition & 2 deletions src/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class expression {
struct condition {

struct cache_type {
std::vector<bool> targets{};
// std::unordered_set<target_index> targets{};
memory::vector<ddwaf_object *> targets;
std::optional<event::match> match;
};

Expand Down

0 comments on commit eae2c65

Please sign in to comment.