Sitelet https://github.com/Vectorized/solady/pull/1428/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/utils/libtransient.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,9 @@ Note: The value pointed to might not be cleared from previous usage.
function peek(TStack storage ptr) internal view returns (bytes32 topPtr)
```

Returns a pointer to the top element. Returns zero if the stack is empty.
This method can help avoid an additional `TLOAD`.
Returns a pointer to the top element. Returns the zero pointer if the stack is empty.
This method can help avoid an additional `TLOAD`, but you MUST check if the
returned pointer is zero. And if it is, please DO NOT read / write to it.

### top(TStack)

Expand Down
5 changes: 3 additions & 2 deletions src/utils/LibTransient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,9 @@ library LibTransient {
}
}

/// @dev Returns a pointer to the top element. Returns zero if the stack is empty.
/// This method can help avoid an additional `TLOAD`.
/// @dev Returns a pointer to the top element. Returns the zero pointer if the stack is empty.
/// This method can help avoid an additional `TLOAD`, but you MUST check if the
/// returned pointer is zero. And if it is, please DO NOT read / write to it.
function peek(TStack storage ptr) internal view returns (bytes32 topPtr) {
/// @solidity memory-safe-assembly
assembly {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/g/LibTransient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,9 @@ library LibTransient {
}
}

/// @dev Returns a pointer to the top element. Returns zero if the stack is empty.
/// This method can help avoid an additional `TLOAD`.
/// @dev Returns a pointer to the top element. Returns the zero pointer if the stack is empty.
/// This method can help avoid an additional `TLOAD`, but you MUST check if the
/// returned pointer is zero. And if it is, please DO NOT read / write to it.
function peek(TStack storage ptr) internal view returns (bytes32 topPtr) {
/// @solidity memory-safe-assembly
assembly {
Expand Down
4 changes: 3 additions & 1 deletion test/LibTransient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ contract LibTransientTest is SoladyTest {

LibTransient.tStack(stackSlot).clear();
assertEq(LibTransient.tStack(stackSlot).peek(), 0);
assertEq(LibTransient.tStack(stackSlot).peek().tBytes32().get(), 0);
if (stackSlot != 0) {
assertEq(LibTransient.tStack(stackSlot).peek().tBytes32().get(), 0);
}

assertEq(LibTransient.tStack(stackSlot).length(), 0);
for (uint256 i; i < n; ++i) {
Expand Down