Skip to content

Commit

Permalink
[MRESOLVER-586] Avoid copying the type default properties map (#535)
Browse files Browse the repository at this point in the history
When we don't have specific properties for a DefaultArtifact, we can
just reuse the type default properties map as it's readonly and
immutable.
The patch contains some additional changes as I renamed the method
and parameters to make them more specific so that the method
wouldn't be used for things that wouldn't be safe.

---

https://issues.apache.org/jira/browse/MRESOLVER-586
  • Loading branch information
gsmet authored Aug 2, 2024
1 parent 29ab557 commit f1be3b9
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,27 @@ public DefaultArtifact(
}
this.version = emptify(version);
this.file = null;
this.properties = merge(properties, (type != null) ? type.getProperties() : null);
this.properties = mergeArtifactProperties(properties, (type != null) ? type.getProperties() : null);
}

private static Map<String, String> merge(Map<String, String> dominant, Map<String, String> recessive) {
private static Map<String, String> mergeArtifactProperties(
Map<String, String> artifactProperties, Map<String, String> typeDefaultProperties) {
Map<String, String> properties;

if ((dominant == null || dominant.isEmpty()) && (recessive == null || recessive.isEmpty())) {
properties = Collections.emptyMap();
if (artifactProperties == null || artifactProperties.isEmpty()) {
if (typeDefaultProperties == null || typeDefaultProperties.isEmpty()) {
properties = Collections.emptyMap();
} else {
// type default properties are already unmodifiable
return typeDefaultProperties;
}
} else {
properties = new HashMap<>();
if (recessive != null) {
properties.putAll(recessive);
if (typeDefaultProperties != null) {
properties.putAll(typeDefaultProperties);
}
if (dominant != null) {
properties.putAll(dominant);
if (artifactProperties != null) {
properties.putAll(artifactProperties);
}
properties = Collections.unmodifiableMap(properties);
}
Expand Down

0 comments on commit f1be3b9

Please sign in to comment.