Skip to content

Commit 19f5f8c

Browse files
committed
Optimize a N-Quads serialization call.
Remove a temporary object and object property manipulation in favor of a direct function call.
1 parent 96d9570 commit 19f5f8c

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Improvement depends on number of digests performed.
2222
- Node.js using the improved browser algorithm can be ~4-9% faster overall.
2323
- Node.js native `Buffer` conversion can be ~5-12% faster overall.
24+
- Optimize a N-Quads serialization call.
2425

2526
### Fixed
2627
- Disable native lib tests in a browser.

lib/URDNA2015.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,15 @@ module.exports = class URDNA2015 {
188188

189189
// 3.1.1) If any component in quad is an blank node, then serialize it
190190
// using a special identifier as follows:
191-
const copy = {
192-
subject: null, predicate: quad.predicate, object: null, graph: null
193-
};
194191
// 3.1.2) If the blank node's existing blank node identifier matches
195192
// the reference blank node identifier then use the blank node
196193
// identifier _:a, otherwise, use the blank node identifier _:z.
197-
copy.subject = this.modifyFirstDegreeComponent(
198-
id, quad.subject, 'subject');
199-
copy.object = this.modifyFirstDegreeComponent(
200-
id, quad.object, 'object');
201-
copy.graph = this.modifyFirstDegreeComponent(
202-
id, quad.graph, 'graph');
203-
nquads.push(NQuads.serializeQuad(copy));
194+
nquads.push(NQuads.serializeQuadComponents(
195+
this.modifyFirstDegreeComponent(id, quad.subject, 'subject'),
196+
quad.predicate,
197+
this.modifyFirstDegreeComponent(id, quad.object, 'object'),
198+
this.modifyFirstDegreeComponent(id, quad.graph, 'graph')
199+
));
204200
}
205201

206202
// 4) Sort nquads in lexicographical order.

lib/URDNA2015Sync.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,15 @@ module.exports = class URDNA2015Sync {
184184

185185
// 3.1.1) If any component in quad is an blank node, then serialize it
186186
// using a special identifier as follows:
187-
const copy = {
188-
subject: null, predicate: quad.predicate, object: null, graph: null
189-
};
190187
// 3.1.2) If the blank node's existing blank node identifier matches
191188
// the reference blank node identifier then use the blank node
192189
// identifier _:a, otherwise, use the blank node identifier _:z.
193-
copy.subject = this.modifyFirstDegreeComponent(
194-
id, quad.subject, 'subject');
195-
copy.object = this.modifyFirstDegreeComponent(
196-
id, quad.object, 'object');
197-
copy.graph = this.modifyFirstDegreeComponent(
198-
id, quad.graph, 'graph');
199-
nquads.push(NQuads.serializeQuad(copy));
190+
nquads.push(NQuads.serializeQuadComponents(
191+
this.modifyFirstDegreeComponent(id, quad.subject, 'subject'),
192+
quad.predicate,
193+
this.modifyFirstDegreeComponent(id, quad.object, 'object'),
194+
this.modifyFirstDegreeComponent(id, quad.graph, 'graph')
195+
));
200196
}
201197

202198
// 4) Sort nquads in lexicographical order.

0 commit comments

Comments
 (0)