Skip to content

Commit

Permalink
Combine objectDependices and objectRequired into propertyExist array
Browse files Browse the repository at this point in the history
  • Loading branch information
miloyip committed Apr 19, 2016
1 parent f586edd commit a6571d5
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions include/rapidjson/schema.h
Expand Up @@ -289,8 +289,7 @@ struct SchemaValidationContext {
patternPropertiesSchemas(),
patternPropertiesSchemaCount(),
valuePatternValidatorType(kPatternValidatorOnly),
objectDependencies(),
objectRequired(),
propertyExist(),
inArray(false),
valueUniqueness(false),
arrayUniqueness(false)
Expand All @@ -312,10 +311,8 @@ struct SchemaValidationContext {
}
if (patternPropertiesSchemas)
factory.FreeState(patternPropertiesSchemas);
if (objectDependencies)
factory.FreeState(objectDependencies);
if (objectRequired)
factory.FreeState(objectRequired);
if (propertyExist)
factory.FreeState(propertyExist);
}

SchemaValidatorFactoryType& factory;
Expand All @@ -333,8 +330,7 @@ struct SchemaValidationContext {
PatternValidatorType valuePatternValidatorType;
PatternValidatorType objectPatternValidatorType;
SizeType arrayElementIndex;
bool* objectDependencies;
bool* objectRequired;
bool* propertyExist;
bool inArray;
bool valueUniqueness;
bool arrayUniqueness;
Expand Down Expand Up @@ -770,14 +766,9 @@ class Schema {
if (!(type_ & (1 << kObjectSchemaType)))
RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());

if (hasRequired_) {
context.objectRequired = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
std::memset(context.objectRequired, 0, sizeof(bool) * propertyCount_);
}

if (hasDependencies_) {
context.objectDependencies = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
std::memset(context.objectDependencies, 0, sizeof(bool) * propertyCount_);
if (hasDependencies_ || hasRequired_) {
context.propertyExist = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
std::memset(context.propertyExist, 0, sizeof(bool) * propertyCount_);
}

if (patternProperties_) { // pre-allocate schema array
Expand Down Expand Up @@ -808,11 +799,8 @@ class Schema {
else
context.valueSchema = properties_[index].schema;

if (hasRequired_)
context.objectRequired[index] = true;

if (hasDependencies_)
context.objectDependencies[index] = true;
if (context.propertyExist)
context.propertyExist[index] = true;

return true;
}
Expand Down Expand Up @@ -840,11 +828,10 @@ class Schema {

bool EndObject(Context& context, SizeType memberCount) const {
if (hasRequired_)
for (SizeType index = 0; index < propertyCount_; index++) {
for (SizeType index = 0; index < propertyCount_; index++)
if (properties_[index].required)
if (!context.objectRequired[index])
if (!context.propertyExist[index])
RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString());
}

if (memberCount < minProperties_)
RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString());
Expand All @@ -854,10 +841,10 @@ class Schema {

if (hasDependencies_) {
for (SizeType sourceIndex = 0; sourceIndex < propertyCount_; sourceIndex++)
if (context.objectDependencies[sourceIndex]) {
if (context.propertyExist[sourceIndex]) {
if (properties_[sourceIndex].dependencies) {
for (SizeType targetIndex = 0; targetIndex < propertyCount_; targetIndex++)
if (properties_[sourceIndex].dependencies[targetIndex] && !context.objectDependencies[targetIndex])
if (properties_[sourceIndex].dependencies[targetIndex] && !context.propertyExist[targetIndex])
RAPIDJSON_INVALID_KEYWORD_RETURN(GetDependenciesString());
}
else if (properties_[sourceIndex].dependenciesSchema)
Expand Down

0 comments on commit a6571d5

Please sign in to comment.