Explorar o código

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

Apple M1 performance fix
Timofey Kachalov %!s(int64=3) %!d(string=hai) anos
pai
achega
a6cab50ff1
Modificáronse 3 ficheiros con 6 adicións e 4 borrados
  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
 ---
 * Dependencies update
+* Fixed performance for Apple M1 chip
 
 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-coverage": "nyc --reporter text-summary --no-clean yarn run test:mocha",
     "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",
     "eslint": "eslint src/**/*.ts",
     "git:addFiles": "git add .",

+ 4 - 3
src/utils/NumberUtils.ts

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