Skip to content

Commit

Permalink
Use an std::stack for frame_sizes on the schema evaluator (#915)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Aug 8, 2024
1 parent 97078b4 commit 8fd0d98
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/jsonschema/compile_evaluate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <limits> // std::numeric_limits
#include <map> // std::map
#include <set> // std::set
#include <stack> // std::stack
#include <type_traits> // std::is_same_v
#include <vector> // std::vector

namespace {

Expand Down Expand Up @@ -72,8 +72,8 @@ class EvaluationContext {

auto push(const Pointer &relative_evaluate_path,
const Pointer &relative_instance_location) -> void {
this->frame_sizes.emplace_back(relative_evaluate_path.size(),
relative_instance_location.size());
this->frame_sizes.emplace(relative_evaluate_path.size(),
relative_instance_location.size());
this->evaluate_path_.push_back(relative_evaluate_path);
this->instance_location_.push_back(relative_instance_location);
}
Expand All @@ -84,10 +84,10 @@ class EvaluationContext {

auto pop() -> void {
assert(!this->frame_sizes.empty());
const auto &sizes{this->frame_sizes.back()};
const auto &sizes{this->frame_sizes.top()};
this->evaluate_path_.pop_back(sizes.first);
this->instance_location_.pop_back(sizes.second);
this->frame_sizes.pop_back();
this->frame_sizes.pop();
}

auto evaluate_path() const -> const Pointer & { return this->evaluate_path_; }
Expand Down Expand Up @@ -209,7 +209,7 @@ class EvaluationContext {
private:
Pointer evaluate_path_;
Pointer instance_location_;
std::vector<std::pair<std::size_t, std::size_t>> frame_sizes;
std::stack<std::pair<std::size_t, std::size_t>> frame_sizes;
std::set<Pointer> annotation_blacklist;
// For efficiency, as we likely reference the same JSON values
// over and over again
Expand Down

0 comments on commit 8fd0d98

Please sign in to comment.