Optimize Bundle Size

This commit is contained in:
MengYX
2020-02-06 14:05:46 +08:00
parent 8680be846f
commit e81c3d82e5
5 changed files with 204 additions and 64 deletions

View File

@@ -96,8 +96,6 @@
// 严格模式 用于尾调用优化
"use strict";
const worker = require("workerize-loader!./decrypt/common");
const dec = require('./decrypt/common');
export default {
name: 'app',
components: {},
@@ -132,12 +130,15 @@
this.finishLoad();
});
if (document.location.host !== "") {
this.thread_num = Math.max(navigator.hardwareConcurrency, 1);
//todo: Fail on Hot Reload
const worker = require("workerize-loader!./decrypt/common");
this.thread_num = navigator.hardwareConcurrency || 1;
for (let i = 0; i < this.thread_num; i++) {
this.workers.push(worker().CommonDecrypt);
this.idle_workers.push(i);
}
} else {
const dec = require('./decrypt/common');
this.workers.push(dec.CommonDecrypt);
this.idle_workers.push(0)
}

View File

@@ -1,6 +1,7 @@
const musicMetadata = require("music-metadata-browser");
const util = require("./util");
export {Decrypt}
const FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43, 0x00];
async function Decrypt(file, raw_filename, raw_ext) {
// 获取扩展名
@@ -45,7 +46,7 @@ async function Decrypt(file, raw_filename, raw_ext) {
}
class Mask {
FLAC_HEADER = [0x66, 0x4C, 0x61, 0x43, 0x00];
constructor() {
this.index = -1;
@@ -69,9 +70,9 @@ class Mask {
if (!flag) continue;
for (let test_idx = 0; test_idx < this.FLAC_HEADER.length; test_idx++) {
for (let test_idx = 0; test_idx < FLAC_HEADER.length; test_idx++) {
let p = data[test_idx] ^ mask[test_idx];
if (p !== this.FLAC_HEADER[test_idx]) {
if (p !== FLAC_HEADER[test_idx]) {
flag = false;
debugger;
break;