Skip to content

Commit 967300f

Browse files
committed
Only compile library.properties schemas once
While it's necessary to do the validation against the schemas for each library, the schemas themselves don't change so there's no need to recompile them for each library checked.
1 parent 21ea159 commit 967300f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

project/library/libraryproperties/libraryproperties.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func Properties(libraryPath *paths.Path) (*properties.Map, error) {
3333
return libraryProperties, nil
3434
}
3535

36+
var schemaObject = make(map[compliancelevel.Type]*jsonschema.Schema)
37+
3638
// Validate validates library.properties data against the JSON schema and returns a map of the result for each compliance level.
3739
func Validate(libraryProperties *properties.Map, schemasPath *paths.Path) map[compliancelevel.Type]*jsonschema.ValidationError {
3840
referencedSchemaFilenames := []string{
@@ -42,14 +44,15 @@ func Validate(libraryProperties *properties.Map, schemasPath *paths.Path) map[co
4244

4345
var validationResults = make(map[compliancelevel.Type]*jsonschema.ValidationError)
4446

45-
schemaObject := schema.Compile("arduino-library-properties-permissive-schema.json", referencedSchemaFilenames, schemasPath)
46-
validationResults[compliancelevel.Permissive] = schema.Validate(libraryProperties, schemaObject, schemasPath)
47-
48-
schemaObject = schema.Compile("arduino-library-properties-schema.json", referencedSchemaFilenames, schemasPath)
49-
validationResults[compliancelevel.Specification] = schema.Validate(libraryProperties, schemaObject, schemasPath)
47+
if schemaObject[compliancelevel.Permissive] == nil { // Only compile the schemas once.
48+
schemaObject[compliancelevel.Permissive] = schema.Compile("arduino-library-properties-permissive-schema.json", referencedSchemaFilenames, schemasPath)
49+
schemaObject[compliancelevel.Specification] = schema.Compile("arduino-library-properties-schema.json", referencedSchemaFilenames, schemasPath)
50+
schemaObject[compliancelevel.Strict] = schema.Compile("arduino-library-properties-strict-schema.json", referencedSchemaFilenames, schemasPath)
51+
}
5052

51-
schemaObject = schema.Compile("arduino-library-properties-strict-schema.json", referencedSchemaFilenames, schemasPath)
52-
validationResults[compliancelevel.Strict] = schema.Validate(libraryProperties, schemaObject, schemasPath)
53+
validationResults[compliancelevel.Permissive] = schema.Validate(libraryProperties, schemaObject[compliancelevel.Permissive], schemasPath)
54+
validationResults[compliancelevel.Specification] = schema.Validate(libraryProperties, schemaObject[compliancelevel.Specification], schemasPath)
55+
validationResults[compliancelevel.Strict] = schema.Validate(libraryProperties, schemaObject[compliancelevel.Strict], schemasPath)
5356

5457
return validationResults
5558
}

0 commit comments

Comments
 (0)