Skip to content

Commit

Permalink
⚡ Optimize extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 9, 2024
1 parent 9f7cea1 commit 87d0ee6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
14 changes: 7 additions & 7 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
IETest:testBalanceInERC20() (gas: 62541)
IETest:testBalanceInETH() (gas: 53683)
IETest:testCommandSendERC0() (gas: 115197)
IETest:testCommandSendETH() (gas: 81697)
IETest:testCommandSendUSDC() (gas: 147933)
IETest:testDeploy() (gas: 1779435)
IETest:testCommandSendERC0() (gas: 114684)
IETest:testCommandSendETH() (gas: 81184)
IETest:testCommandSendUSDC() (gas: 147420)
IETest:testDeploy() (gas: 1772219)
IETest:testENSNameFromENSHelper() (gas: 29125)
IETest:testENSNameOwnership() (gas: 109154)
IETest:testIENameSetting() (gas: 8174)
IETest:testPreviewCommandSendDecimals() (gas: 113368)
IETest:testPreviewCommandSendUSDC() (gas: 78237)
IETest:testPreviewCommandSendDecimals() (gas: 112342)
IETest:testPreviewCommandSendUSDC() (gas: 77724)
IETest:testPreviewSend() (gas: 54699)
IETest:testPreviewSendCommand() (gas: 67451)
IETest:testPreviewSendCommand() (gas: 66938)
IETest:testSendETH() (gas: 70975)
IETest:testTotalSupply() (gas: 14810)
23 changes: 11 additions & 12 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,19 @@ contract IE {

/// @dev Extracts the first word from a string and returns it as a bytes32 (action).
function _extraction(string memory normalizedIntent) internal pure returns (bytes32) {
bytes memory stringBytes = bytes(normalizedIntent);
uint256 endIndex = stringBytes.length;
for (uint256 i = 0; i < stringBytes.length; ++i) {
if (stringBytes[i] == 0x20) {
// ASCII space
endIndex = i;
break;
unchecked {
bytes memory stringBytes = bytes(normalizedIntent);
bytes32 result;
uint256 length = stringBytes.length > 32 ? 32 : stringBytes.length;
for (uint256 i; i != length; ++i) {
// Stop copying if a space is found.
if (stringBytes[i] == 0x20) {
break;
}
result |= bytes32(stringBytes[i] & 0xFF) >> (i * 8);
}
return result;
}
bytes32 word;
for (uint256 i = 0; i < endIndex; ++i) {
word |= bytes32(stringBytes[i] & 0xFF) >> (i * 8);
}
return word;
}

/// @dev Extract key words of normalized `send` intent.
Expand Down

0 comments on commit 87d0ee6

Please sign in to comment.