Skip to content
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

feat(store,world): move hooks to bit flags #1527

Merged
merged 3 commits into from
Sep 17, 2023
Merged

feat(store,world): move hooks to bit flags #1527

merged 3 commits into from
Sep 17, 2023

Conversation

holic
Copy link
Member

@holic holic commented Sep 17, 2023

closes #1459

TODO:

@changeset-bot
Copy link

changeset-bot bot commented Sep 17, 2023

🦋 Changeset detected

Latest commit: 2545542

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
@latticexyz/store Major
@latticexyz/world Major
@latticexyz/cli Major
@latticexyz/dev-tools Major
@latticexyz/react Major
@latticexyz/store-indexer Major
@latticexyz/store-sync Major
@latticexyz/abi-ts Major
@latticexyz/block-logs-stream Major
@latticexyz/common Major
@latticexyz/config Major
create-mud Major
@latticexyz/ecs-browser Major
@latticexyz/faucet Major
@latticexyz/gas-report Major
@latticexyz/network Major
@latticexyz/noise Major
@latticexyz/phaserx Major
@latticexyz/protocol-parser Major
@latticexyz/recs Major
@latticexyz/schema-type Major
@latticexyz/services Major
@latticexyz/solecs Major
solhint-config-mud Major
solhint-plugin-mud Major
@latticexyz/std-client Major
@latticexyz/std-contracts Major
@latticexyz/store-cache Major
@latticexyz/utils Major

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

@holic holic changed the title feat(store,world): move hooks to bitmaps with bitwise operators feat(store,world): move hooks to bit flags Sep 17, 2023
Comment on lines -55 to +56
function isEnabled(Hook self, uint8 hookType) internal pure returns (bool) {
// Pick the bitmap encoded in the rightmost byte from the hook and check if the bit at the given hook type is set
return (getBitmap(self) & (1 << uint8(hookType))) != 0;
function isEnabled(Hook self, uint8 hookTypes) internal pure returns (bool) {
return (getBitmap(self) & hookTypes) == hookTypes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨✨✨ so much nicer


uint8 constant BEFORE_SET_RECORD = 1 << 0;
uint8 constant AFTER_SET_RECORD = 1 << 1;
// TODO: do we need to differentiate between static and dynamic set field?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cross posting here from discord for context: the "set field" hook is soon replaced with a "splice" hook (see #1510)

alvrs
alvrs previously approved these changes Sep 17, 2023
Copy link
Member

@alvrs alvrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@alvrs alvrs marked this pull request as ready for review September 17, 2023 13:53
@alvrs alvrs requested a review from dk1a as a code owner September 17, 2023 13:53
@alvrs
Copy link
Member

alvrs commented Sep 17, 2023

expand bitmap to uint16 or uint32 for more bits/hooks

don't think this will be necessary since we'll only have 6 hooks (before/after set, splice, delete)

Edit: it's 8 (before/after set, splice static, splice dynamic, delete) but still fits in 8 bit

@alvrs alvrs merged commit 759514d into main Sep 17, 2023
@alvrs alvrs deleted the holic/hook-bitmaps branch September 17, 2023 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use bitwise OR for hook bitmaps
2 participants