Skip to content

Commit 217c46a

Browse files
committed
performance: separate method to looup single char
1 parent 000de2d commit 217c46a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/xmlparser/OrderedObjParser.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,12 @@ function findClosingIndex(xmlData, str, i, errMsg) {
779779
}
780780
}
781781

782+
function findClosingChar(xmlData, char, i, errMsg) {
783+
const closingIndex = xmlData.indexOf(char, i);
784+
if (closingIndex === -1) throw new Error(errMsg);
785+
return closingIndex; // no offset needed
786+
}
787+
782788
function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
783789
const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
784790
if (!result) return;
@@ -824,7 +830,7 @@ function readStopNodeData(xmlData, tagName, i) {
824830
if (xmlData[i] === "<") {
825831
const c1 = xmlData.charCodeAt(i + 1);
826832
if (c1 === 47) {//close tag '/'
827-
const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
833+
const closeIndex = findClosingChar(xmlData, ">", i, `${tagName} is not closed`);
828834
let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
829835
if (closeTagName === tagName) {
830836
openTagCount--;

0 commit comments

Comments
 (0)