Skip to content

Commit

Permalink
perf: add emitNodes to skip checking text buffer more than needed
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Aug 22, 2018
1 parent d605913 commit 9d5e357
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,25 @@ class SaxesParser {
this[nodeType](data);
}

/**
* Emit any buffered text. Then emit the specified node types.
*
* @param {string} nodeTypeA The node type to emit.
*
* @param {string} nodeTypeB The node type to emit.
*
* @param {string} data The data associated with the node type.
*
* @private
*/
emitNodes(nodeTypeA, nodeTypeB, data) {
if (this.textNode) {
this.closeText();
}
this[nodeTypeA](data);
this[nodeTypeB](data);
}

resolve(prefix) {
let uri = this.tag.ns[prefix];
if (uri !== undefined) {
Expand Down Expand Up @@ -1713,16 +1732,16 @@ class SaxesParser {
this.fail("documents may contain only one root.");
}
this.sawRoot = true;
this.emitNode("onopentag", tag);
const { tags } = this;
if (selfClosing) {
this.emitNode("onclosetag", tag);
this.emitNodes("onopentag", "onclosetag", tag);
this.tag = tags[tags.length - 1];
if (!this.tag) {
this.closedRoot = true;
}
}
else {
this.emitNode("onopentag", tag);
this.inRoot = true;
tags.push(tag);
}
Expand Down

0 comments on commit 9d5e357

Please sign in to comment.