Skip to content

Commit 2e8ca59

Browse files
authored
feat: SparseCalldataSegmentLib optimization (#200)
1 parent c75f885 commit 2e8ca59

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/helpers/EmptyCalldataSlice.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
pragma solidity ^0.8.20;
3+
4+
function getEmptyCalldataSlice() pure returns (bytes calldata) {
5+
bytes calldata empty;
6+
7+
assembly ("memory-safe") {
8+
empty.length := 0
9+
}
10+
11+
return empty;
12+
}

src/libraries/SparseCalldataSegmentLib.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.20;
33

44
import {RESERVED_VALIDATION_DATA_INDEX} from "../helpers/Constants.sol";
5+
import {getEmptyCalldataSlice} from "../helpers/EmptyCalldataSlice.sol";
56

67
/// @title Sparse Calldata Segment Library
78
/// @notice Library for working with sparsely-packed calldata segments, identified with an index.
@@ -51,7 +52,7 @@ library SparseCalldataSegmentLib {
5152
function advanceSegmentIfAtIndex(bytes calldata source, uint8 index)
5253
internal
5354
pure
54-
returns (bytes memory, bytes calldata)
55+
returns (bytes calldata, bytes calldata)
5556
{
5657
uint8 nextIndex = getIndex(source);
5758

@@ -69,7 +70,7 @@ library SparseCalldataSegmentLib {
6970
return (segment, remainder);
7071
}
7172

72-
return ("", source);
73+
return (getEmptyCalldataSlice(), source);
7374
}
7475

7576
/// @notice Extracts the final segment from the source.

0 commit comments

Comments
 (0)