From 749601b4eeb4c2d4d6d6ffc162a9a61ff53d3930 Mon Sep 17 00:00:00 2001 From: Shebin John Date: Thu, 9 Jan 2025 13:22:01 +0100 Subject: [PATCH] G-03. ERC165Handler.setSupportedInterface(): Logic and storage access optimization --- contracts/handler/extensible/ERC165Handler.sol | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/contracts/handler/extensible/ERC165Handler.sol b/contracts/handler/extensible/ERC165Handler.sol index 4833ddcdf..cf3ece3ed 100644 --- a/contracts/handler/extensible/ERC165Handler.sol +++ b/contracts/handler/extensible/ERC165Handler.sol @@ -35,13 +35,15 @@ abstract contract ERC165Handler is ExtensibleBase, IERC165Handler { ISafe safe = ISafe(payable(_manager())); // invalid interface id per ERC165 spec require(interfaceId != 0xffffffff, "invalid interface id"); - bool current = safeInterfaces[safe][interfaceId]; - if (supported && !current) { - safeInterfaces[safe][interfaceId] = true; - emit AddedInterface(safe, interfaceId); - } else if (!supported && current) { - delete safeInterfaces[safe][interfaceId]; - emit RemovedInterface(safe, interfaceId); + mapping(bytes4 => bool) storage safeInterface = safeInterfaces[safe]; + bool current = safeInterface[interfaceId]; + if (supported != current) { + safeInterface[interfaceId] = supported; + if (supported) { + emit AddedInterface(safe, interfaceId); + } else { + emit RemovedInterface(safe, interfaceId); + } } }