From 1ae42b69a8c64452c3a5f03a672b384950020842 Mon Sep 17 00:00:00 2001 From: Pradyumna Kattel <126577744+pradyumna14@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:51:17 +0530 Subject: [PATCH] Update Counters.sol This optimization is beneficial in scenarios where counters are updated frequently, like tracking tokens, votes, or similar operations, providing potential gas savings while maintaining compatibility with existing contracts using the library. --- smart-contracts/contracts/Counters.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smart-contracts/contracts/Counters.sol b/smart-contracts/contracts/Counters.sol index 0781b50..14a7a9d 100644 --- a/smart-contracts/contracts/Counters.sol +++ b/smart-contracts/contracts/Counters.sol @@ -11,8 +11,9 @@ library Counters { } function increment(Counter storage counter) internal { + uint256 value = counter._value; unchecked { - counter._value += 1; + counter._value = value + 1; } }