浏览代码

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

Book Pauk 6 年之前
父节点
当前提交
db3ecde741
共有 2 个文件被更改,包括 8 次插入11 次删除
  1. 6 9
      server/core/BookConverter/easysaxmod.js
  2. 2 2
      server/core/BookConverter/index.js

+ 6 - 9
server/core/BookConverter/easysaxmod.js

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

+ 2 - 2
server/core/BookConverter/index.js

@@ -89,7 +89,7 @@ class BookConverter {
                         growParagraph('<strong>');
                         break;
                     case 'div':
-                        const a = getAttr();
+                        var a = getAttr();
                         if (a && a.align == 'center')
                             center = true;
                         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';
         for (const charset of charsetAll) {