Skip to content

Commit

Permalink
perf: eliminate extra buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
lddubeau committed Oct 3, 2019
1 parent edd86e1 commit 3412fcb
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ class SaxesParser {
this.openWakaBang = "";
this.text = "";
this.name = "";
this.doctype = "";
this.piTarget = "";
this.piBody = "";
this.entity = "";
Expand Down Expand Up @@ -1223,6 +1222,9 @@ class SaxesParser {
if (this.doctype || this.sawRoot) {
this.fail("inappropriately located doctype declaration.");
}
if (this.text.length !== 0) {
this.closeText();
}
this.openWakaBang = "";
break;
default:
Expand All @@ -1236,20 +1238,18 @@ class SaxesParser {

/** @private */
sDoctype() {
const c = this.captureTo(DOCTYPE_TERMINATOR, "doctype");
const c = this.captureTo(DOCTYPE_TERMINATOR, "text");
switch (c) {
case GREATER:
this.ondoctype(this.text);
this.text = "";
this.state = S_TEXT;
if (this.text.length !== 0) {
this.closeText();
}
this.ondoctype(this.doctype);
this.doctype = true; // just remember that we saw it.
break;
case EOC:
break;
default:
this.doctype += String.fromCodePoint(c);
this.text += String.fromCodePoint(c);
if (c === OPEN_BRACKET) {
this.state = S_DTD;
}
Expand All @@ -1263,21 +1263,21 @@ class SaxesParser {
/** @private */
sDoctypeQuote() {
const { q } = this;
if (this.captureToChar(q, "doctype")) {
this.doctype += String.fromCodePoint(q);
if (this.captureToChar(q, "text")) {
this.text += String.fromCodePoint(q);
this.q = null;
this.state = S_DOCTYPE;
}
}

/** @private */
sDTD() {
const c = this.captureTo(DTD_TERMINATOR, "doctype");
const c = this.captureTo(DTD_TERMINATOR, "text");
if (c === EOC) {
return;
}

this.doctype += String.fromCodePoint(c);
this.text += String.fromCodePoint(c);
if (c === CLOSE_BRACKET) {
this.state = S_DOCTYPE;
}
Expand All @@ -1293,8 +1293,8 @@ class SaxesParser {
/** @private */
sDTDQuoted() {
const { q } = this;
if (this.captureToChar(q, "doctype")) {
this.doctype += String.fromCodePoint(q);
if (this.captureToChar(q, "text")) {
this.text += String.fromCodePoint(q);
this.state = S_DTD;
this.q = null;
}
Expand All @@ -1303,7 +1303,7 @@ class SaxesParser {
/** @private */
sDTDOpenWaka() {
const c = this.getCode();
this.doctype += String.fromCodePoint(c);
this.text += String.fromCodePoint(c);
switch (c) {
case BANG:
this.state = S_DTD_OPEN_WAKA_BANG;
Expand All @@ -1321,7 +1321,7 @@ class SaxesParser {
sDTDOpenWakaBang() {
const char = String.fromCodePoint(this.getCode());
const owb = this.openWakaBang += char;
this.doctype += char;
this.text += char;
if (owb !== "-") {
this.state = owb === "--" ? S_DTD_COMMENT : S_DTD;
this.openWakaBang = "";
Expand All @@ -1330,23 +1330,23 @@ class SaxesParser {

/** @private */
sDTDComment() {
if (this.captureToChar(MINUS, "doctype")) {
this.doctype += "-";
if (this.captureToChar(MINUS, "text")) {
this.text += "-";
this.state = S_DTD_COMMENT_ENDING;
}
}

/** @private */
sDTDCommentEnding() {
const c = this.getCode();
this.doctype += String.fromCodePoint(c);
this.text += String.fromCodePoint(c);
this.state = c === MINUS ? S_DTD_COMMENT_ENDED : S_DTD_COMMENT;
}

/** @private */
sDTDCommentEnded() {
const c = this.getCode();
this.doctype += String.fromCodePoint(c);
this.text += String.fromCodePoint(c);
if (c === GREATER) {
this.state = S_DTD;
}
Expand All @@ -1360,16 +1360,16 @@ class SaxesParser {

/** @private */
sDTDPI() {
if (this.captureToChar(QUESTION, "doctype")) {
this.doctype += "?";
if (this.captureToChar(QUESTION, "text")) {
this.text += "?";
this.state = S_DTD_PI_ENDING;
}
}

/** @private */
sDTDPIEnding() {
const c = this.getCode();
this.doctype += String.fromCodePoint(c);
this.text += String.fromCodePoint(c);
if (c === GREATER) {
this.state = S_DTD;
}
Expand Down

0 comments on commit 3412fcb

Please sign in to comment.