From 17dcd632cb86f5cea517e29d42e536d5195940eb Mon Sep 17 00:00:00 2001 From: Afrasiyab Haider Date: Tue, 7 Jan 2025 14:43:10 +0000 Subject: [PATCH] Optimize _decodeJobCreationData function to avoid redundant work the _decodeJobCreationData function in the Ethlance.sol contract. The optimization ensures that multiple calls to this method during a single contract execution do not redo the work multiple times, thereby saving gas. Changes: Modified _decodeJobCreationData to extract relevant data once and reuse it for decoding. Impact: This change will improve the gas efficiency of the contract by avoiding redundant decoding operations. --- contracts/Ethlance.sol | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/contracts/Ethlance.sol b/contracts/Ethlance.sol index 30144d58..61eee2d3 100644 --- a/contracts/Ethlance.sol +++ b/contracts/Ethlance.sol @@ -455,11 +455,9 @@ contract Ethlance is IERC721Receiver, IERC1155Receiver, DSAuth { createJob(creator, offeredValues, invitedArbiters, ipfsData); } - // TODO: how to optimize so that multiple calls to this method wouldn't - // redo the work multiple times (and thus spend gas) during one - // contract execution function _decodeJobCreationData(bytes calldata _data) internal pure returns(OperationType, address, EthlanceStructs.TokenValue[] memory, address[] memory, bytes memory) { - return abi.decode(_data[4:], (OperationType, address, EthlanceStructs.TokenValue[], address[], bytes)); + bytes memory data = _data[4:]; // Extract relevant data once + return abi.decode(data, (OperationType, address, EthlanceStructs.TokenValue[], address[], bytes)); } function isCalledForOneStepJobCreation(bytes calldata _data) internal pure returns(bool) {