Skip to content

Commit

Permalink
Optimize a N-Quads serialization call.
Browse files Browse the repository at this point in the history
Remove a temporary object and object property manipulation in favor of a
direct function call.
  • Loading branch information
davidlehn committed Mar 28, 2023
1 parent 96d9570 commit 19f5f8c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Improvement depends on number of digests performed.
- Node.js using the improved browser algorithm can be ~4-9% faster overall.
- Node.js native `Buffer` conversion can be ~5-12% faster overall.
- Optimize a N-Quads serialization call.

### Fixed
- Disable native lib tests in a browser.
Expand Down
16 changes: 6 additions & 10 deletions lib/URDNA2015.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,15 @@ module.exports = class URDNA2015 {

// 3.1.1) If any component in quad is an blank node, then serialize it
// using a special identifier as follows:
const copy = {
subject: null, predicate: quad.predicate, object: null, graph: null
};
// 3.1.2) If the blank node's existing blank node identifier matches
// the reference blank node identifier then use the blank node
// identifier _:a, otherwise, use the blank node identifier _:z.
copy.subject = this.modifyFirstDegreeComponent(
id, quad.subject, 'subject');
copy.object = this.modifyFirstDegreeComponent(
id, quad.object, 'object');
copy.graph = this.modifyFirstDegreeComponent(
id, quad.graph, 'graph');
nquads.push(NQuads.serializeQuad(copy));
nquads.push(NQuads.serializeQuadComponents(
this.modifyFirstDegreeComponent(id, quad.subject, 'subject'),
quad.predicate,
this.modifyFirstDegreeComponent(id, quad.object, 'object'),
this.modifyFirstDegreeComponent(id, quad.graph, 'graph')
));
}

// 4) Sort nquads in lexicographical order.
Expand Down
16 changes: 6 additions & 10 deletions lib/URDNA2015Sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,15 @@ module.exports = class URDNA2015Sync {

// 3.1.1) If any component in quad is an blank node, then serialize it
// using a special identifier as follows:
const copy = {
subject: null, predicate: quad.predicate, object: null, graph: null
};
// 3.1.2) If the blank node's existing blank node identifier matches
// the reference blank node identifier then use the blank node
// identifier _:a, otherwise, use the blank node identifier _:z.
copy.subject = this.modifyFirstDegreeComponent(
id, quad.subject, 'subject');
copy.object = this.modifyFirstDegreeComponent(
id, quad.object, 'object');
copy.graph = this.modifyFirstDegreeComponent(
id, quad.graph, 'graph');
nquads.push(NQuads.serializeQuad(copy));
nquads.push(NQuads.serializeQuadComponents(
this.modifyFirstDegreeComponent(id, quad.subject, 'subject'),
quad.predicate,
this.modifyFirstDegreeComponent(id, quad.object, 'object'),
this.modifyFirstDegreeComponent(id, quad.graph, 'graph')
));
}

// 4) Sort nquads in lexicographical order.
Expand Down

0 comments on commit 19f5f8c

Please sign in to comment.