danielsun1106 commented on a change in pull request #1561:
URL: https://github.com/apache/groovy/pull/1561#discussion_r613659839
##########
File path: src/main/java/org/codehaus/groovy/classgen/asm/OperandStack.java
##########
@@ -331,19 +332,13 @@ private void doConvertAndCast(ClassNode targetType, final
boolean coerce) {
ClassNode top = stack.get(size - 1);
targetType = targetType.redirect();
- if (targetType == top) return;
+ if (ClassNodeUtils.isCompatibleWith(top, targetType)) return;
if (coerce) {
controller.getInvocationWriter().coerce(top, targetType);
return;
}
- // GROOVY-10034: no need to cast non-primitive array when target is
"java.lang.Object[]"
- if (targetType.isArray() &&
targetType.getComponentType().equals(ClassHelper.OBJECT_TYPE)
- && top.isArray() &&
!ClassHelper.isPrimitiveType(top.getComponentType())) {
- return;
- }
Review comment:
> I thought the goal was to simplify from GROOVY-10034. Now we have
multiple new public APIs to support? Object[] can accept any kind of array
regardless of dimension, except one-dimensional primitive array. This was
accounted for in the original condition.
Actually the goal is to tweak the fix for GROOVY-10034, not only simplify
the check but also make it general to eliminate more redundant type cast.
( See https://github.com/apache/groovy/pull/1556#discussion_r611815705 )
> targetType == top is a much faster comparison then always making a method
call. == or .equals should probably be kept before making a method call.
OK. Let's add the check `targetType == top` before `isCompatibleWith` method
call for better performance.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]