Skip to content

Commit

Permalink
⚡ Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Feb 9, 2024
1 parent 0e7b157 commit 9f7cea1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 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: 115797)
IETest:testCommandSendETH() (gas: 82297)
IETest:testCommandSendUSDC() (gas: 148533)
IETest:testDeploy() (gas: 1806509)
IETest:testCommandSendERC0() (gas: 115197)
IETest:testCommandSendETH() (gas: 81697)
IETest:testCommandSendUSDC() (gas: 147933)
IETest:testDeploy() (gas: 1779435)
IETest:testENSNameFromENSHelper() (gas: 29125)
IETest:testENSNameOwnership() (gas: 109154)
IETest:testIENameSetting() (gas: 8174)
IETest:testPreviewCommandSendDecimals() (gas: 114569)
IETest:testPreviewCommandSendUSDC() (gas: 78837)
IETest:testPreviewCommandSendDecimals() (gas: 113368)
IETest:testPreviewCommandSendUSDC() (gas: 78237)
IETest:testPreviewSend() (gas: 54699)
IETest:testPreviewSendCommand() (gas: 68051)
IETest:testPreviewSendCommand() (gas: 67451)
IETest:testSendETH() (gas: 70975)
IETest:testTotalSupply() (gas: 14810)
15 changes: 8 additions & 7 deletions src/IE.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,22 @@ contract IE {

/// ================= INTERNAL STRING OPERATIONS ================= ///

/// @dev Extracts first word (action) from a string.
function _extraction(string memory normalizedIntent) internal pure virtual returns (bytes32) {
/// @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; i != stringBytes.length; ++i) {
for (uint256 i = 0; i < stringBytes.length; ++i) {
if (stringBytes[i] == 0x20) {
// ASCII space
endIndex = i;
break;
}
}
bytes memory firstWordBytes = new bytes(endIndex);
for (uint256 i; i != endIndex; ++i) {
firstWordBytes[i] = stringBytes[i];
bytes32 word;
for (uint256 i = 0; i < endIndex; ++i) {
word |= bytes32(stringBytes[i] & 0xFF) >> (i * 8);
}
return bytes32(firstWordBytes);
return word;
}

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

0 comments on commit 9f7cea1

Please sign in to comment.