Skip to content

Commit

Permalink
Merge pull request #130 from zazuko/list-perf
Browse files Browse the repository at this point in the history
perf: reuse sh:in nodeSet
  • Loading branch information
giacomociti committed Apr 16, 2024
2 parents f2411d6 + 1329680 commit 1bb0383
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-points-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rdf-validate-shacl": patch
---

Improve performance of validating `sh:in` constraints
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"@changesets/cli": "^2.22.0",
"@rdfjs/parser-n3": "^2.0.1",
"@tpluscode/eslint-config": "^0.4.4",
"@zazuko/env-node": "^2",
"c8": "^8.0.1",
"get-stream": "^6.0.0",
"mocha": "^10.2.0",
"nanoid": "^4.0.2",
"@zazuko/env-node": "^2",
"rdf-ext": "^2.5.1",
"rdf-utils-dataset": "^2.0.0"
},
Expand Down
8 changes: 6 additions & 2 deletions src/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ function validateHasValueProperty(context, focusNode, valueNode, constraint) {

function validateIn(context, focusNode, valueNode, constraint) {
const { sh } = context.ns
const inNode = constraint.getParameterValue(sh.in)
if (!constraint.nodeSet) {
const inNode = constraint.getParameterValue(sh.in)
constraint.nodeSet = new NodeSet(rdfListToArray(context.$shapes.node(inNode)))
}
const { nodeSet } = constraint

return new NodeSet(rdfListToArray(context.$shapes.node(inNode))).has(valueNode)
return nodeSet.has(valueNode)
}

function validateLanguageIn(context, focusNode, valueNode, constraint) {
Expand Down

0 comments on commit 1bb0383

Please sign in to comment.