Skip to content

Commit

Permalink
fix(store): minor gas report fixes, padding (#1156)
Browse files Browse the repository at this point in the history
* fix padding

* fix gas reports that were optimized out
  • Loading branch information
dk1a authored Jul 13, 2023
1 parent db19ea3 commit 184d5b5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
10 changes: 5 additions & 5 deletions packages/store/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
"file": "test/Bytes.t.sol",
"test": "testSetBytes1",
"name": "set bytes1 in bytes32",
"gasUsed": 1
"gasUsed": 16
},
{
"file": "test/Bytes.t.sol",
"test": "testSetBytes2",
"name": "set bytes2 in bytes32",
"gasUsed": 1
"gasUsed": 16
},
{
"file": "test/Bytes.t.sol",
"test": "testSetBytes4",
"name": "set bytes4 in bytes32",
"gasUsed": 1
"gasUsed": 16
},
{
"file": "test/Bytes.t.sol",
Expand Down Expand Up @@ -207,13 +207,13 @@
"file": "test/Slice.t.sol",
"test": "testFromBytes",
"name": "get Slice length",
"gasUsed": 1
"gasUsed": 10
},
{
"file": "test/Slice.t.sol",
"test": "testFromBytes",
"name": "get Slice pointer",
"gasUsed": 27
"gasUsed": 33
},
{
"file": "test/Slice.t.sol",
Expand Down
9 changes: 6 additions & 3 deletions packages/store/test/Bytes.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ contract BytesTest is Test, GasReporter {
bytes32 input = bytes32(0);

startGasReport("set bytes1 in bytes32");
Bytes.setBytes1(input, 8, 0xff);
bytes32 output = Bytes.setBytes1(input, 8, 0xff);
endGasReport();

assertEq(output, hex"0000000000000000ff");
assertEq(Bytes.setBytes1(input, 0, 0x01), bytes32(bytes1(0x01)));
assertEq(Bytes.setBytes1(input, 31, 0x01), bytes32(uint256(0x01)));
}
Expand All @@ -103,9 +104,10 @@ contract BytesTest is Test, GasReporter {
bytes32 input = bytes32(0);

startGasReport("set bytes2 in bytes32");
Bytes.setBytes2(input, 8, 0xffff);
bytes32 output = Bytes.setBytes2(input, 8, 0xffff);
endGasReport();

assertEq(output, hex"0000000000000000ffff");
assertEq(Bytes.setBytes2(input, 0, 0xffff), bytes32(bytes2(0xffff)));
assertEq(Bytes.setBytes2(input, 30, 0xffff), bytes32(uint256(0xffff)));
}
Expand All @@ -114,9 +116,10 @@ contract BytesTest is Test, GasReporter {
bytes32 input = bytes32(0);

startGasReport("set bytes4 in bytes32");
Bytes.setBytes4(input, 8, 0xffffffff);
bytes32 output = Bytes.setBytes4(input, 8, 0xffffffff);
endGasReport();

assertEq(output, hex"0000000000000000ffffffff");
assertEq(Bytes.setBytes4(input, 0, 0xffffffff), bytes32(bytes4(0xffffffff)));
assertEq(Bytes.setBytes4(input, 30, 0xffffffff), bytes32(uint256(0xffff)));
assertEq(Bytes.setBytes4(input, 28, 0xffffffff), bytes32(uint256(0xffffffff)));
Expand Down
8 changes: 4 additions & 4 deletions packages/store/test/Slice.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ contract SliceTest is Test, GasReporter {
endGasReport();

startGasReport("get Slice length");
slice.length();
uint256 length = slice.length();
endGasReport();

startGasReport("get Slice pointer");
slice.pointer();
uint256 pointer = slice.pointer();
endGasReport();

assertEq(slice.length(), 8);
assertEq(slice.pointer(), Memory.dataPointer(data));
assertEq(length, 8);
assertEq(pointer, Memory.dataPointer(data));
assertEq(slice.toBytes(), data);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/store/ts/codegen/ephemeral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export function renderEphemeralMethods(options: RenderTableOptions) {
_typedKeyArgs,
`${structName} memory _table`,
])}) internal {
emitEphemeral(${renderArguments([
_untypedStore,
_tableId,
_keyArgs,
renderArguments(options.fields.map(({ name }) => `_table.${name}`)),
])});
emitEphemeral(${renderArguments([
_untypedStore,
_tableId,
_keyArgs,
renderArguments(options.fields.map(({ name }) => `_table.${name}`)),
])});
}
`
);
Expand Down

0 comments on commit 184d5b5

Please sign in to comment.