From 145a51bd4303bd2dd6ef0814d9655a145391ecb3 Mon Sep 17 00:00:00 2001 From: Fabrice Mouhartem Date: Wed, 5 Aug 2026 14:13:25 +0200 Subject: [PATCH] =?UTF-8?q?perf(sortify):=20don=E2=80=99t=20redefine=20isN?= =?UTF-8?q?umericalExpr=20everytime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + style --- src/common/common-util.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/common-util.js b/src/common/common-util.js index d252ef482..0415978f8 100644 --- a/src/common/common-util.js +++ b/src/common/common-util.js @@ -857,6 +857,7 @@ const factory = (NaclUtil) => { }; /* End of code copied from saferphore */ + const isNumericalExpr = /^(0|[1-9]\d*)$/; const sortKeys = obj => { if (Array.isArray(obj)) { return obj.map(sortKeys); @@ -865,13 +866,13 @@ const factory = (NaclUtil) => { let numeric = []; let nonNumeric = []; Object.keys(obj).forEach(key => { - if (/^(0|[1-9]\d*)$/.test(key)) { + if (isNumericalExpr.test(key)) { numeric.push(+key); } else { nonNumeric.push(key); } }); - return numeric.sort((a,b) => a - b).concat(nonNumeric.sort()).reduce((result, key) => { + return numeric.sort((a, b) => a - b).concat(nonNumeric.sort()).reduce((result, key) => { result[key] = sortKeys(obj[key]); return result; }, {});