Commit f34fb5f1 authored by Johnny Lim's avatar Johnny Lim Committed by Stephane Nicoll

Reduce object creation in findMatchingItemMetadata()

Closes gh-13473
parent 27bb4614
...@@ -145,10 +145,11 @@ public class ConfigurationMetadata { ...@@ -145,10 +145,11 @@ public class ConfigurationMetadata {
} }
private ItemMetadata findMatchingItemMetadata(ItemMetadata metadata) { private ItemMetadata findMatchingItemMetadata(ItemMetadata metadata) {
List<ItemMetadata> candidates = getCandidates(metadata.getName()); List<ItemMetadata> candidates = this.items.get(metadata.getName());
if (candidates.isEmpty()) { if (candidates == null || candidates.isEmpty()) {
return null; return null;
} }
candidates = new ArrayList<>(candidates);
candidates.removeIf((itemMetadata) -> !itemMetadata.hasSameType(metadata)); candidates.removeIf((itemMetadata) -> !itemMetadata.hasSameType(metadata));
if (candidates.size() > 1 && metadata.getType() != null) { if (candidates.size() > 1 && metadata.getType() != null) {
candidates.removeIf( candidates.removeIf(
...@@ -165,11 +166,6 @@ public class ConfigurationMetadata { ...@@ -165,11 +166,6 @@ public class ConfigurationMetadata {
return null; return null;
} }
private List<ItemMetadata> getCandidates(String name) {
List<ItemMetadata> candidates = this.items.get(name);
return (candidates != null ? new ArrayList<>(candidates) : new ArrayList<>());
}
private boolean nullSafeEquals(Object o1, Object o2) { private boolean nullSafeEquals(Object o1, Object o2) {
if (o1 == o2) { if (o1 == o2) {
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment