-
-
Notifications
You must be signed in to change notification settings - Fork 406
Support for the SyntaxInfo suppliers #8124
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
base: dev/patch
Are you sure you want to change the base?
Conversation
…gacy api, replaced reflection calls for creating instances of syntax infos with LambdaMetafactory
…ch/syntaxinfo-supply # Conflicts: # src/main/java/ch/njol/skript/lang/SkriptParser.java # src/main/java/ch/njol/skript/lang/SyntaxElementInfo.java
Co-authored-by: Efnilite <[email protected]>
Co-authored-by: Efnilite <[email protected]>
Co-authored-by: Efnilite <[email protected]>
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.
Overall looks good. I'm not sure the instance supplier changes for the legacy SyntaxElementInfo classes are necessary, given they are unused internally (apart from maybe docs, but that doesn't matter)
return supplier == null ? type.getDeclaredConstructor().newInstance() : supplier.get(); | ||
} catch (ReflectiveOperationException e) { | ||
throw new RuntimeException(e); | ||
if (supplier == null) { |
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 think it'd be fine to set the supplier when the object is constructed so that the field can continue to be final.
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 think creating a lot of metafactories can get fairly expensive so I wanted to initialize them lazily. I'll check the performance cost during startup and see how bad it gets.
@@ -16,4 +23,36 @@ public static boolean isNormalClass(Class<?> clazz) { | |||
&& !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers()); | |||
} | |||
|
|||
private static final Map<Class<?>, Supplier<?>> instanceSuppliers = new ConcurrentHashMap<>(); |
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.
Do you think a cache is necessary? The method would probably only be called once per registered syntax, right?
Problem
The syntax info suppliers developers can provide in the new API are lost during the conversion to SyntaxElementInfo.
Solution
SyntaxElementInfo now stores its instance supplier. If none is provided, it uses the nullary constructor instead.
I also replaced repeated reflection calls with Supplier created using LambdaMetafactory that delegates to the nullary constructor.
Testing Completed
quick test
Completes: none
Related: none