Skip to content

Commit

Permalink
feat: SparseCalldataSegmentLib optimization (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypaik authored Oct 15, 2024
1 parent c75f885 commit 2e8ca59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/helpers/EmptyCalldataSlice.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;

function getEmptyCalldataSlice() pure returns (bytes calldata) {
bytes calldata empty;

assembly ("memory-safe") {
empty.length := 0
}

return empty;
}
5 changes: 3 additions & 2 deletions src/libraries/SparseCalldataSegmentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.20;

import {RESERVED_VALIDATION_DATA_INDEX} from "../helpers/Constants.sol";
import {getEmptyCalldataSlice} from "../helpers/EmptyCalldataSlice.sol";

/// @title Sparse Calldata Segment Library
/// @notice Library for working with sparsely-packed calldata segments, identified with an index.
Expand Down Expand Up @@ -51,7 +52,7 @@ library SparseCalldataSegmentLib {
function advanceSegmentIfAtIndex(bytes calldata source, uint8 index)
internal
pure
returns (bytes memory, bytes calldata)
returns (bytes calldata, bytes calldata)
{
uint8 nextIndex = getIndex(source);

Expand All @@ -69,7 +70,7 @@ library SparseCalldataSegmentLib {
return (segment, remainder);
}

return ("", source);
return (getEmptyCalldataSlice(), source);
}

/// @notice Extracts the final segment from the source.
Expand Down

0 comments on commit 2e8ca59

Please sign in to comment.