Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: reuse sh:in nodeSet #130

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@rdfjs/dataset": "^2",
"@rdfjs/environment": "^1",
"@rdfjs/namespace": "^2.0.0",
"@rdfjs/term-map": "^2.0.1",
"@rdfjs/term-set": "^2.0.1",
"@vocabulary/sh": "^1.0.1",
"clownface": "^2.0.0",
Expand All @@ -36,11 +37,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
11 changes: 10 additions & 1 deletion src/validators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { validateTerm } from 'rdf-validate-datatype'
import { fromRdf } from 'rdf-literal'
import TermMap from '@rdfjs/term-map'
import NodeSet from './node-set.js'
import { getPathObjects } from './property-path.js'
import { isInstanceOf, rdfListToArray } from './dataset-utils.js'
Expand Down Expand Up @@ -133,8 +134,16 @@ function validateHasValueProperty(context, focusNode, valueNode, constraint) {
function validateIn(context, focusNode, valueNode, constraint) {
const { sh } = context.ns
const inNode = constraint.getParameterValue(sh.in)
if (!constraint.nodeSets) {
constraint.nodeSets = new TermMap()
}
let nodeSet = constraint.nodeSets.get(inNode)
if (!nodeSet) {
nodeSet = new NodeSet(rdfListToArray(context.$shapes.node(inNode)))
constraint.nodeSets.set(inNode, nodeSet)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a list of node sets? I would expect a constraint object to represent a single sh:in constraint

Suggested change
const inNode = constraint.getParameterValue(sh.in)
if (!constraint.nodeSets) {
constraint.nodeSets = new TermMap()
}
let nodeSet = constraint.nodeSets.get(inNode)
if (!nodeSet) {
nodeSet = new NodeSet(rdfListToArray(context.$shapes.node(inNode)))
constraint.nodeSets.set(inNode, nodeSet)
}
if (!constraint.nodeSet) {
const inNode = constraint.getParameterValue(sh.in)
constraint.nodeSet = new NodeSet(rdfListToArray(context.$shapes.node(inNode)))
constraint.nodeSet = new TermMap()
}
const { nodeSet } = constraint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that all the shapes with a sh:in constraint are sharing the same instance

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. getParameterValue gets the sh:in from the shape pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct


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

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