Skip to content

Commit 9272ced

Browse files
kowsikrobrighter
authored andcommitted
down from 4m2s to 1m30s for a 1MB xml file
1 parent 98f08bc commit 9272ced

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lib/node-xml.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ XMLP.prototype._parse = function() {
234234
return XMLP._NONE;
235235
}
236236

237-
if(this.m_iP == this.m_xml.indexOf("<?", this.m_iP)) {
237+
var fc = this.m_xml.charAt(this.m_iP);
238+
if (fc !== '<' && fc !== '&') {
239+
return this._parseText (this.m_iP);
240+
}
241+
else if(this.m_iP == this.m_xml.indexOf("<?", this.m_iP)) {
238242
return this._parsePI (this.m_iP + 2);
239243
}
240244
else if(this.m_iP == this.m_xml.indexOf("<!DOCTYPE", this.m_iP)) {
@@ -599,17 +603,24 @@ XMLP.prototype._parsePI = function(iB) {
599603
}
600604

601605
XMLP.prototype._parseText = function(iB) {
602-
var iE, iEE;
606+
var iE, ch;
603607

604-
iE = this.m_xml.indexOf("<", iB);
605-
if(iE == -1) {
606-
iE = this.m_xml.length;
607-
}
608-
609-
iEE = this.m_xml.indexOf("&", iB);
610-
if((iEE != -1) && (iEE <= iE)) {
611-
iE = iEE;
608+
for (iE=iB; iE<this.m_xml.length; ++iE) {
609+
ch = this.m_xml.charAt(iE);
610+
if (ch === '<' || ch === '&') {
611+
break;
612+
}
612613
}
614+
615+
// iE = this.m_xml.indexOf("<", iB);
616+
// if(iE == -1) {
617+
// iE = this.m_xml.length;
618+
// }
619+
//
620+
// iEE = this.m_xml.indexOf("&", iB);
621+
// if((iEE != -1) && (iEE <= iE)) {
622+
// iE = iEE;
623+
// }
613624

614625
this._setContent(XMLP._CONT_XML, iB, iE);
615626

0 commit comments

Comments
 (0)