|
|
@@ -58,7 +58,7 @@ private:
|
|
|
ValidationResult * result_;
|
|
|
|
|
|
ValidationConfig const & cfg_;
|
|
|
- std::unordered_map<std::string, RE> & regex_cache_;
|
|
|
+ RE & regex_;
|
|
|
|
|
|
mutable VisitedAnnotation * visited_ = nullptr;
|
|
|
mutable StoreResults tracking_ = StoreResults::ForInvalid;
|
|
|
@@ -69,14 +69,14 @@ public:
|
|
|
*
|
|
|
* @param schema The parsed JSON Schema
|
|
|
* @param cfg General configuration settings for how the run is executed
|
|
|
- * @param regex_cache A cache of string regular expressions to compiled
|
|
|
+ * @param regex A cache of string regular expressions to compiled
|
|
|
* regular expressions
|
|
|
* @param[optional] result A cache of result/annotation info for the user to
|
|
|
* receive a detailed summary of why a document is supported/unsupported.
|
|
|
*/
|
|
|
- ValidationVisitor(schema::Node const & schema, ValidationConfig const & cfg,
|
|
|
- std::unordered_map<std::string, RE> & regex_cache, ValidationResult * result)
|
|
|
- : schema_(&schema), result_(result), cfg_(cfg), regex_cache_(regex_cache) {}
|
|
|
+ ValidationVisitor(schema::Node const & schema, ValidationConfig const & cfg, RE & regex,
|
|
|
+ ValidationResult * result)
|
|
|
+ : schema_(&schema), result_(result), cfg_(cfg), regex_(regex) {}
|
|
|
|
|
|
Status visit(constraint::TypeConstraint const & cons, Adapter auto const & document) const {
|
|
|
adapter::Type const type = document.type();
|
|
|
@@ -257,9 +257,8 @@ public:
|
|
|
Status visit(constraint::PatternConstraint const & cons, Adapter auto const & document) const {
|
|
|
NOOP_UNLESS_TYPE(String);
|
|
|
|
|
|
- RE const & regex = regex_cache_.try_emplace(cons.regex, cons.regex).first->second;
|
|
|
std::string const str = document.as_string();
|
|
|
- if (regex.search(str)) {
|
|
|
+ if (regex_.search(cons.regex, str)) {
|
|
|
return result(Status::Accept, "string matches pattern /", cons.regex, "/");
|
|
|
}
|
|
|
return result(Status::Reject, "string does not match pattern /", cons.regex, "/");
|
|
|
@@ -383,8 +382,7 @@ public:
|
|
|
|
|
|
auto matches_any_pattern = [this, &cons](std::string const & key) {
|
|
|
for (auto & pattern : cons.patterns) {
|
|
|
- RE const & regex = regex_cache_.try_emplace(pattern, pattern).first->second;
|
|
|
- if (regex.search(key)) {
|
|
|
+ if (regex_.search(pattern, key)) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
@@ -462,9 +460,8 @@ public:
|
|
|
std::vector<std::string> properties;
|
|
|
Status rval = Status::Accept;
|
|
|
for (auto const & [pattern, subschema] : cons.properties) {
|
|
|
- RE const & regex = regex_cache_.try_emplace(pattern, pattern).first->second;
|
|
|
for (auto const & [key, elem] : document.as_object()) {
|
|
|
- if (not regex.search(key)) {
|
|
|
+ if (not regex_.search(pattern, key)) {
|
|
|
continue;
|
|
|
}
|
|
|
VALIDATE_SUBSCHEMA_AND_MARK_LOCAL_VISIT(subschema, elem, key, properties);
|