ソースを参照

Merge pull request #1041 from javascript-obfuscator/m1-performance

Apple M1 performance fix
Timofey Kachalov 3 年 前
コミット
a6cab50ff1
3 ファイル変更6 行追加4 行削除
  1. 1 0
      CHANGELOG.md
  2. 1 1
      package.json
  3. 4 3
      src/utils/NumberUtils.ts

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@ Change Log
 v3.0.1
 v3.0.1
 ---
 ---
 * Dependencies update
 * Dependencies update
+* Fixed performance for Apple M1 chip
 
 
 v3.0.0
 v3.0.0
 ---
 ---

+ 1 - 1
package.json

@@ -111,7 +111,7 @@
     "test:mocha": "mocha --require ts-node/register --require source-map-support/register test/index.spec.ts --exit",
     "test:mocha": "mocha --require ts-node/register --require source-map-support/register test/index.spec.ts --exit",
     "test:mocha-coverage": "nyc --reporter text-summary --no-clean yarn run test:mocha",
     "test:mocha-coverage": "nyc --reporter text-summary --no-clean yarn run test:mocha",
     "test:mocha-coverage:report": "nyc report --reporter=lcov",
     "test:mocha-coverage:report": "nyc report --reporter=lcov",
-    "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=220 mocha --require ts-node/register test/performance-tests/JavaScriptObfuscatorMemory.spec.ts",
+    "test:mocha-memory-performance": "cross-env NODE_OPTIONS=--max-old-space-size=230 mocha --require ts-node/register test/performance-tests/JavaScriptObfuscatorMemory.spec.ts",
     "test": "yarn run test:full",
     "test": "yarn run test:full",
     "eslint": "eslint src/**/*.ts",
     "eslint": "eslint src/**/*.ts",
     "git:addFiles": "git add .",
     "git:addFiles": "git add .",

+ 4 - 3
src/utils/NumberUtils.ts

@@ -104,14 +104,15 @@ export class NumberUtils {
             currentFactor <= root;
             currentFactor <= root;
             currentFactor += incrementValue
             currentFactor += incrementValue
         ) {
         ) {
-            if (number % currentFactor !== 0) {
+            const compliment: number = number / currentFactor;
+            const check = (number - Math.floor(compliment) * currentFactor) !== 0;
+
+            if (check) {
                 continue;
                 continue;
             }
             }
 
 
             factors.push(...[-currentFactor, currentFactor]);
             factors.push(...[-currentFactor, currentFactor]);
 
 
-            const compliment: number = number / currentFactor;
-
             if (compliment !== currentFactor) {
             if (compliment !== currentFactor) {
                 factors.push(...[-compliment, compliment]);
                 factors.push(...[-compliment, compliment]);
             }
             }