[#3947] Avoid creating unnecessary Iterators and ArrayLists in AbstractStore.getAttachables()
This commit is contained in:
parent
e248376121
commit
5031910d2a
@ -59,6 +59,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -143,16 +144,19 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
|
||||
@Override
|
||||
final List<Attachable> getAttachables() {
|
||||
List<Attachable> result = new ArrayList<Attachable>();
|
||||
List<Attachable> result = null;
|
||||
|
||||
int size = size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (values[i] instanceof Attachable) {
|
||||
if (result == null)
|
||||
result = new ArrayList<Attachable>();
|
||||
|
||||
result.add((Attachable) values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result == null ? Collections.<Attachable>emptyList() : result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -85,9 +85,10 @@ abstract class AbstractStore implements AttachableInternal {
|
||||
public final void attach(Configuration c) {
|
||||
configuration = c;
|
||||
|
||||
for (Attachable attachable : getAttachables()) {
|
||||
attachable.attach(c);
|
||||
}
|
||||
final List<Attachable> attachables = getAttachables();
|
||||
final int size = attachables.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
attachables.get(i).attach(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user