Rikkola commented on code in PR #6460:
URL:
https://github.com/apache/incubator-kie-drools/pull/6460#discussion_r2361886866
##########
drools-mvel/src/main/java/org/drools/mvel/accessors/BaseDecimalClassFieldReader.java:
##########
@@ -24,7 +24,7 @@
import org.drools.base.base.BaseClassFieldReader;
import org.drools.base.base.ValueType;
-public abstract class BaseCharClassFieldReader extends BaseClassFieldReader {
+public abstract class BaseDecimalClassFieldReader extends BaseClassFieldReader
{
Review Comment:
I am using new names Decimal and WholeNumber. This made helped when
refactoring to catch the locations where the code was generated against the
removed and updated methods/classes, but we can rename these to Double and Long
if wanted.
##########
drools-mvel/src/main/java/org/drools/mvel/asm/ClassFieldAccessorFactory.java:
##########
@@ -347,7 +347,28 @@ protected static void buildGetMethod(final Class< ? >
originalClass,
Type.getMethodDescriptor( getterMethod ),
false);
}
- mv.visitInsn( Type.getType( fieldType ).getOpcode( Opcodes.IRETURN ) );
+ if (getterMethod.getReturnType() != overridingMethod.getReturnType()) {
+ if (getterMethod.getReturnType() == float.class &&
overridingMethod.getReturnType() == double.class) {
+ mv.visitInsn(Opcodes.F2D); // Convert float to double
+ // Clean up precision artifacts from float-to-double conversion
+ mv.visitMethodInsn(Opcodes.INVOKESTATIC,
+ "org/drools/util/FloatHelper",
+ "cleanDouble",
+ "(D)D",
+ false);
+ } else if (getterMethod.getReturnType() == double.class &&
overridingMethod.getReturnType() == float.class) {
+ mv.visitInsn(Opcodes.D2F); // Convert double to float
+ } else if (getterMethod.getReturnType() == byte.class &&
overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert byte to long
(byte->int->long handled by JVM)
+ } else if (getterMethod.getReturnType() == short.class &&
overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert short to long
(short->int->long handled by JVM)
+ } else if (getterMethod.getReturnType() == int.class &&
overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert int to long
+ } else if (getterMethod.getReturnType() == char.class &&
overridingMethod.getReturnType() == long.class) {
+ mv.visitInsn(Opcodes.I2L); // Convert char to long
(char->int->long handled by JVM)
+ }
+ }
+ mv.visitInsn( Type.getType( overridingMethod.getReturnType()
).getOpcode( Opcodes.IRETURN ) );
Review Comment:
One of the concerns is if this slows things down? Since I suspect the
benefits before and after this PR was that there was direct access to the value
and now we need to convert.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]