From 8fd0d98b982e965e45eb1f002319ae64bf969e90 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 8 Aug 2024 11:46:28 -0400 Subject: [PATCH] Use an `std::stack` for `frame_sizes` on the schema evaluator (#915) Signed-off-by: Juan Cruz Viotti --- src/jsonschema/compile_evaluate.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jsonschema/compile_evaluate.cc b/src/jsonschema/compile_evaluate.cc index ff103a26c..3725207af 100644 --- a/src/jsonschema/compile_evaluate.cc +++ b/src/jsonschema/compile_evaluate.cc @@ -9,8 +9,8 @@ #include // std::numeric_limits #include // std::map #include // std::set +#include // std::stack #include // std::is_same_v -#include // std::vector namespace { @@ -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); } @@ -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_; } @@ -209,7 +209,7 @@ class EvaluationContext { private: Pointer evaluate_path_; Pointer instance_location_; - std::vector> frame_sizes; + std::stack> frame_sizes; std::set annotation_blacklist; // For efficiency, as we likely reference the same JSON values // over and over again