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

Encoder: Maybe speed up last node holders #191

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
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
22 changes: 11 additions & 11 deletions core/src/main/scala/eu/ostrzyciel/jelly/core/ProtoEncoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,21 @@ abstract class ProtoEncoder[TNode, -TTriple, -TQuad, -TQuoted](val options: RdfS
private val lastSubject: LastNodeHolder[TNode] = new LastNodeHolder()
private val lastPredicate: LastNodeHolder[TNode] = new LastNodeHolder()
private val lastObject: LastNodeHolder[TNode] = new LastNodeHolder()
private val lastGraph: LastNodeHolder[TNode] = new LastNodeHolder()
private var lastGraph: TNode | LastNodeHolder.NoValue.type = LastNodeHolder.NoValue

private def nodeToProtoWrapped(node: TNode, lastNodeHolder: LastNodeHolder[TNode]): SpoTerm =
lastNodeHolder.node match
case oldNode if node == oldNode => null
case _ =>
lastNodeHolder.node = node
nodeToProto(node)
if node.equals(lastNodeHolder.node) then null
else
lastNodeHolder.node = node
nodeToProto(node)

private def graphNodeToProtoWrapped(node: TNode): GraphTerm =
lastGraph.node match
case oldNode if node == oldNode => null
case _ =>
lastGraph.node = node
graphNodeToProto(node)
// Graph nodes may be null in Jena for example... so we need to handle that.
if (node == null && lastGraph == null) || (node != null && node.equals(lastGraph)) then
null
else
lastGraph = node
graphNodeToProto(node)

private def tripleToProto(triple: TTriple): RdfTriple =
RdfTriple(
Expand Down