From 0c0e75aa1301bb6edb6133b0171fd1383d694643 Mon Sep 17 00:00:00 2001 From: ross <92001561+z0r0z@users.noreply.github.com> Date: Fri, 9 Feb 2024 07:43:46 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20len?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gas-snapshot | 6 +++--- src/IE.sol | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index fd43896..4c5b155 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,8 +1,8 @@ IETest:testBalanceIn() (gas: 61352) -IETest:testDeploy() (gas: 1812338) +IETest:testDeploy() (gas: 1811938) IETest:testNameFromHelper() (gas: 29061) IETest:testNameOwnership() (gas: 109019) IETest:testNameSetting() (gas: 8174) -IETest:testPreviewCommand() (gas: 79206) -IETest:testPreviewCommandDecimals() (gas: 145486) +IETest:testPreviewCommand() (gas: 79033) +IETest:testPreviewCommandDecimals() (gas: 145004) IETest:testTotalSupply() (gas: 14695) \ No newline at end of file diff --git a/src/IE.sol b/src/IE.sol index f11d3a7..d103cb8 100644 --- a/src/IE.sol +++ b/src/IE.sol @@ -359,12 +359,13 @@ contract IE { returns (string memory) { unchecked { + uint256 len = bytes(base).length; bytes memory baseBytes = bytes(base); - bytes memory result = new bytes(baseBytes.length + 1); - for (uint256 i; i != baseBytes.length; ++i) { + bytes memory result = new bytes(len + 1); + for (uint256 i; i != len; ++i) { result[i] = baseBytes[i]; } - result[baseBytes.length] = value; + result[len] = value; return string(result); } }