-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Bytes32x2Set #5442
base: master
Are you sure you want to change the base?
Add Bytes32x2Set #5442
Conversation
🦋 Changeset detectedLatest commit: eb050b8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
bytes32[2][] _values; | ||
// Position is the index of the value in the `values` array plus 1. | ||
// Position 0 is used to mean a value is not in the self. | ||
mapping(bytes32 valueHash => uint256) _positions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapping(bytes32 valueHash => uint256) _positions; | |
mapping(bytes32 valueHash => uint256) _positionsPlusOne; |
Thoughts on this for code clarity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into the history of this piece of code:
EnumerableSet
was introduced in 2.5. In that version, the code only supported addresses, and the structure was defined as:
struct AddressSet {
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (address => uint256) index;
address[] values;
}
- In version 3.0, the inner/outer structure was used, with the default being a bytes32 set that is
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping (bytes32 => uint256) _indexes;
}
-
In version 5.0, the naming was changed to was we have currently (this is the PR). Note that the PR was the result of an audit issue.
-
This PR is just reusing the wording that we have in the other sets.
IMO:
- No user should touch that storage (if we could make it private we would)
- The description is really clear
- Overall, I tend to favor short names to long ones. IMO
_positionsPlusOne
is difficult/long to read and offer little benefit. - Changing the name in the existing set would be breaking, and using a different name here would be inconsistent.
So I'd personally keep it that way. @ernestognw WDYT ?
PR Checklist
npx changeset add
)