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

Streamline object operations through a better SlotMap interface #1533

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

gbrail
Copy link
Collaborator

@gbrail gbrail commented Jul 21, 2024

Implement a "compute" method which allows a bunch of the logic in ScriptableObject work without as many slot map operations, especially when changing slot instance types.

Also, get a particular check out of the slot map implementations that has always bothered me and move it to ScriptableObject for better encapsulation of language-specific behavior.

Implement a "compute" method which allows a bunch of the logic in
ScriptableObject work without as many slot map operations, especially
when changing slot instance types.

Also, get a particular check out of the slot map implementations that
has always bothered me and move it to ScriptableObject for better
encapsulation of language-specific behavior.
@gbrail gbrail merged commit b7ece52 into mozilla:master Jul 22, 2024
3 checks passed
@gbrail gbrail deleted the better-slot-map branch July 22, 2024 21:24
Slot foundNewSlot = map.query("foo", 0);
assertEquals("Testing", foundNewSlot.value);
assertSame(foundNewSlot, newSlot);
map.remove("foo", 0);
map.compute("foo", 0, (k, ii, e) -> null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, but for me this code looks absolutely unreadable - i guess nobody is able to understand what this line of code does. It might be technically clever to do it like this but from a maintainers point of view i need more support.

Please think (again) about better method naming and at least add some jdoc to this magic method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I never fully grasped how the Slots and SlotMaps worked and was wondering when I saw this PR coming by whether we could have some blogpost-style explainer of it, either in the Wiki or in the documentation

@rbri
Copy link
Collaborator

rbri commented Jul 23, 2024

Hi @gbrail,
i'm really happy with the speed you currently have at merging important things in. Hope we can use this momentum to bring this lib at least a bit forward.
But having only one or two days to review this kind of changes seem to be a bit short - while we spend weeks discussing other changes back and forth several times in all the details.

Just my two cents...

@@ -363,14 +363,27 @@ public void delete(String name) {
@Override
public void delete(int index) {
checkNotSealed(null, index);
slotMap.remove(null, index);
slotMap.compute(null, index, ScriptableObject::checkSlotRemoval);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we already take into consideration here that eventually the delete operation needs to start returning true or false, indicating whether the delete indeed occurred or not?

I know the 'delete' method of the Scriptable interface has a void return type, but this is wrong from an EcmaScript pov, so it would be good to al least make sure that the internal implementation can already properly handle this

@gbrail
Copy link
Collaborator Author

gbrail commented Jul 23, 2024 via email

@rbri
Copy link
Collaborator

rbri commented Jul 23, 2024

'm open to putting an explicit "remove" back in the SlotMap interface if it makes the code clearer.

That was also my first idea - to have some readable wrappers but finally i think adding some jdoc to the method and maybe better naming (in this case maybe a really long name makes sense) will be fine for me

@gbrail
Copy link
Collaborator Author

gbrail commented Jul 23, 2024 via email

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.

3 participants