An array is copied element by element in a loop

tx0/java:manual-array-copystrictwarningperformance

What it finds

for (int i = 0; i < n; i++) target[i] = source[i]; copies one element per pass, where System.arraycopy or Arrays.copyOf copy the block at once and say what happens.

Reported is a counting for loop whose only statement assigns a[i] = b[i], with the same counter on both sides.

From the rule's source, manual_array_copy.rs.

Example from the rule's tests
class Copy {  void copy(int[] source, int[] target, int n) {    for (int i = 0; i < n; i++) {      target[i] = source[i];tx0 reports: System.arraycopy does it at once    }    for (int i = 0; i < n; i++) {      target[i] = source[i] * 2;    }  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:manual-array-copy" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:manual-array-copy] reason="..."

tx0 explain tx0/java:manual-array-copy shows the same in the terminal. Found a false positive? Report it.