Skip to content

Commit f1be3b9

Browse files
authored
[MRESOLVER-586] Avoid copying the type default properties map (#535)
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
1 parent 29ab557 commit f1be3b9

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

maven-resolver-api/src/main/java/org/eclipse/aether/artifact/DefaultArtifact.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,27 @@ public DefaultArtifact(
173173
}
174174
this.version = emptify(version);
175175
this.file = null;
176-
this.properties = merge(properties, (type != null) ? type.getProperties() : null);
176+
this.properties = mergeArtifactProperties(properties, (type != null) ? type.getProperties() : null);
177177
}
178178

179-
private static Map<String, String> merge(Map<String, String> dominant, Map<String, String> recessive) {
179+
private static Map<String, String> mergeArtifactProperties(
180+
Map<String, String> artifactProperties, Map<String, String> typeDefaultProperties) {
180181
Map<String, String> properties;
181182

182-
if ((dominant == null || dominant.isEmpty()) && (recessive == null || recessive.isEmpty())) {
183-
properties = Collections.emptyMap();
183+
if (artifactProperties == null || artifactProperties.isEmpty()) {
184+
if (typeDefaultProperties == null || typeDefaultProperties.isEmpty()) {
185+
properties = Collections.emptyMap();
186+
} else {
187+
// type default properties are already unmodifiable
188+
return typeDefaultProperties;
189+
}
184190
} else {
185191
properties = new HashMap<>();
186-
if (recessive != null) {
187-
properties.putAll(recessive);
192+
if (typeDefaultProperties != null) {
193+
properties.putAll(typeDefaultProperties);
188194
}
189-
if (dominant != null) {
190-
properties.putAll(dominant);
195+
if (artifactProperties != null) {
196+
properties.putAll(artifactProperties);
191197
}
192198
properties = Collections.unmodifiableMap(properties);
193199
}

0 commit comments

Comments
 (0)