mbien commented on a change in pull request #3166:
URL: https://github.com/apache/netbeans/pull/3166#discussion_r720142289
##########
File path: java/java.hints/src/org/netbeans/modules/java/hints/perf/Tiny.java
##########
@@ -314,15 +323,22 @@ private static ErrorDescription enumHint(HintContext ctx,
String baseName, Strin
@Hint(displayName =
"#DN_org.netbeans.modules.java.hints.perf.Tiny.collectionsToArray",
description =
"#DESC_org.netbeans.modules.java.hints.perf.Tiny.collectionsToArray",
category="performance",
- enabled=false,
+ enabled=true,
suppressWarnings="CollectionsToArray")
- @TriggerPattern(value = "$collection.toArray(new $clazz[0])",
- constraints=@ConstraintVariableType(variable="$collection",
-
type="java.util.Collection"))
+ @TriggerPatterns({
+ @TriggerPattern(value = "$collection.toArray(new
$clazz[$collection.size()])",
+ constraints =
@ConstraintVariableType(variable="$collection", type="java.util.Collection")),
+ @TriggerPattern(value = "$collection.toArray(new $clazz[0])",
Review comment:
the thought process was as follows:
`list.toArray(String[]::new)` is cleaner and less hacky than
`list.toArray(new String[0])` which looks like sub optimal code for some
(although both have identical performance on modern JVMs - see updated PR
text). IDEs also advised against it for a long time. Someone might add
col.size() again not knowing the details and we are where we started.
The same inspection can be used to refactor from array-with-zero to
array-with-new if the source lvl allows it, which should be best practice for
11+.
on 8 it refactors `new String[list.size()]` to `new String[0]`,
on 11+ it refactors both `new String[0]` and `new String[list.size()]` to
`list.toArray(String[]::new)`.
--
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]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists