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

More Keyword Tweaks #6694

Open
wants to merge 4 commits into
base: dev/feature
Choose a base branch
from
Open

Conversation

APickledWalrus
Copy link
Member

Description

This PR makes some tweaks to the Keyword class to improve simplicity.

I have removed the flatten utility method. Instead, a recursive approach is taken for building keyword(s) from a choice pattern (it will only go one level down from the root for choices). I have replaced GroupKeyword with ChoiceKeyword is a set of the keywords for each choice. The same idea follows that one of the sets of keywords must apply for the input expression to match.

I've also added some overrides to the keyword implementations (idk about the hashcode implementations).

Some brief testing indicated a possible minor performance increase, though the goal is really only to maintain performance (while improving the implementation).


Target Minecraft Versions: any
Requirements: none
Related Issues: none

ChoiceKeywords add support for more advanced choice groups
@APickledWalrus APickledWalrus added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label May 13, 2024
Comment on lines +78 to +82
Set<Set<Keyword>> choices = ((ChoicePatternElement) next).getPatternElements().stream()
.map(element -> buildKeywords(element, finalStarting, finalDepth))
.map(ImmutableSet::copyOf)
.collect(Collectors.toSet());
if (choices.stream().noneMatch(Collection::isEmpty)) // each choice must have a keyword for this to work
Copy link
Member

Choose a reason for hiding this comment

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

This looks kind of messy and inefficient, especially all the repeated collection copying. Maybe it would be faster to do it properly?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could use Set<Keyword[]> rather than a Set of Sets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants