mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
27 lines
814 B
HTML
27 lines
814 B
HTML
<html>
|
|
<body>
|
|
Reports calls to <code>java.util.Set.removeAll()</code> with a <code>java.util.List</code> argument.
|
|
<p>
|
|
Such a call can be slow when the size of the argument is greater than or equal to the size of the set,
|
|
and the set is a subclass of <code>java.util.AbstractSet</code>.
|
|
In this case, <code>List.contains()</code> is called for each element in the set, which will perform a linear search.
|
|
</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
public void check(String... ss) {
|
|
// possible O(n^2) complexity
|
|
mySet.removeAll(List.of(ss));
|
|
}
|
|
</code></pre>
|
|
<p>After the quick fix is applied:</p>
|
|
<pre><code>
|
|
public void check(String... ss) {
|
|
// O(n) complexity
|
|
List.of(ss).forEach(mySet::remove);
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p><small>New in 2020.3</small></p>
|
|
</body>
|
|
</html>
|