Affects PMD Version:
6.25.0
Description:
AvoidArrayLoops flags array copy asignment within loop as sub-optimal. An example can be added how to resolve the violation.
Code Sample demonstrating the issue:
package ds; public class InsertionSort extends AbstractSort { @Override protected void sort(long[] a, int length) { int in; int out; resetCounts(); for (out = 1; out < length; out++) { long temp = a[out]; in = out; while (in > 0 && a[in - 1] >= temp) { a[in] = a[in - 1]; --in; comparisonCount++; copyCount++; } if (in > 0) comparisonCount++; a[in] = temp; copyCount++; } } }
The optimised loop , no longer flagged by the rule, is as follows:
in = out; while (in > 0 && a[in - 1] >= temp) { --in; ++comparisonCount; ++copyCount; } System.arraycopy(a, in, a, in + 1, out - in);
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4