rspec/rules/S3047/rule.adoc
2022-02-04 16:28:24 +00:00

32 lines
633 B
Plaintext

When a method loops multiple over the same set of data, whether it's a list or a set of numbers, it is highly likely that the method could be made more efficient by combining the loops into a single set of iterations.
== Noncompliant Code Example
[source,text]
----
public void doSomethingToAList(List<String> strings) {
for (String str : strings) {
doStep1(str);
}
for (String str : strings) { // Noncompliant
doStep2(str);
}
}
----
== Compliant Solution
[source,text]
----
public void doSomethingToAList(List<String> strings) {
for (String str : strings) {
doStep1(str);
doStep2(str);
}
}
----