Оптимизация конвертации по скорости

This commit is contained in:
Book Pauk
2019-01-22 22:22:59 +07:00
parent f2eb0d29af
commit db3ecde741
2 changed files with 8 additions and 11 deletions

View File

@@ -433,6 +433,7 @@ function EasySAXParser(config) {
async function parse() { async function parse() {
var stacknsmatrix = []; var stacknsmatrix = [];
var nodestack = []; var nodestack = [];
var nodestackCopy = [];
var stopIndex = 0; var stopIndex = 0;
var _nsmatrix; var _nsmatrix;
var isTagStart = false; var isTagStart = false;
@@ -574,27 +575,22 @@ function EasySAXParser(config) {
//return; //return;
} }
let poped = [];
x = elem = nodestack.pop(); x = elem = nodestack.pop();
poped.push(elem);
q = i + 2 + elem.length; q = i + 2 + elem.length;
while (nodestack.length && elem !== xml.substring(i + 2, q)) { while (nodestack.length && elem !== xml.substring(i + 2, q)) {
onError(returnError = 'close tag, not equal to the open tag'); onError(returnError = 'close tag, not equal to the open tag');
//return; //return;
x = elem = nodestack.pop(); x = elem = nodestack.pop();
poped.push(elem);
q = i + 2 + elem.length; q = i + 2 + elem.length;
} }
if (elem === xml.substring(i + 2, q))
poped.unshift();
if (nodestack.length == 0) { if (nodestack.length == 0) {
while (poped.length) { nodestack = nodestackCopy.slice();
nodestack.push(poped.pop());
}
isTagEnd = false; isTagEnd = false;
} else {
if (elem === xml.substring(i + 2, q))
nodestackCopy = nodestack.slice();
} }
// проверим что в закрываюшем теге нет лишнего // проверим что в закрываюшем теге нет лишнего
@@ -647,6 +643,7 @@ function EasySAXParser(config) {
if (!isTagEnd) { if (!isTagEnd) {
nodestack.push(elem); nodestack.push(elem);
nodestackCopy.push(elem);
} }
} }

View File

@@ -89,7 +89,7 @@ class BookConverter {
growParagraph('<strong>'); growParagraph('<strong>');
break; break;
case 'div': case 'div':
const a = getAttr(); var a = getAttr();
if (a && a.align == 'center') if (a && a.align == 'center')
center = true; center = true;
break; break;
@@ -177,7 +177,7 @@ class BookConverter {
}); });
*/ */
const charsetAll = chardet.detectAll(data); const charsetAll = chardet.detectAll(data.slice(0, 10000));
let selected = 'ISO-8859-1'; let selected = 'ISO-8859-1';
for (const charset of charsetAll) { for (const charset of charsetAll) {