Skip to content

Commit 252a8c2

Browse files
committed
revert most of the mmap changes to focus on the most severe problem
1 parent 6accca2 commit 252a8c2

File tree

2 files changed

+11
-59
lines changed

2 files changed

+11
-59
lines changed

maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/AbstractDependencyManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,23 @@ public DependencyManager deriveChildManager(DependencyCollectionContext context)
151151
String version = artifact.getVersion();
152152
if (!version.isEmpty() && !managedVersions.containsKey(key)) {
153153
if (managedVersions == this.managedVersions) {
154-
managedVersions = MMap.append(this.managedVersions);
154+
managedVersions = MMap.copy(this.managedVersions);
155155
}
156156
managedVersions.put(key, new Holder<>(depth, version));
157157
}
158158

159159
String scope = managedDependency.getScope();
160160
if (!scope.isEmpty() && !managedScopes.containsKey(key)) {
161161
if (managedScopes == this.managedScopes) {
162-
managedScopes = MMap.append(this.managedScopes);
162+
managedScopes = MMap.copy(this.managedScopes);
163163
}
164164
managedScopes.put(key, new Holder<>(depth, scope));
165165
}
166166

167167
Boolean optional = managedDependency.getOptional();
168168
if (optional != null && !managedOptionals.containsKey(key)) {
169169
if (managedOptionals == this.managedOptionals) {
170-
managedOptionals = MMap.append(this.managedOptionals);
170+
managedOptionals = MMap.copy(this.managedOptionals);
171171
}
172172
managedOptionals.put(key, new Holder<>(depth, optional));
173173
}
@@ -177,7 +177,7 @@ public DependencyManager deriveChildManager(DependencyCollectionContext context)
177177
: systemDependencyScope.getSystemPath(managedDependency.getArtifact());
178178
if (localPath != null && !managedLocalPaths.containsKey(key)) {
179179
if (managedLocalPaths == this.managedLocalPaths) {
180-
managedLocalPaths = MMap.append(this.managedLocalPaths);
180+
managedLocalPaths = MMap.copy(this.managedLocalPaths);
181181
}
182182
managedLocalPaths.put(key, new Holder<>(depth, localPath));
183183
}

maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/MMap.java

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Collection;
2323
import java.util.HashMap;
2424
import java.util.Map;
25-
import java.util.Objects;
2625

2726
/**
2827
* Warning: this is a special map-like construct that suits only and should be used only in this package!
@@ -52,17 +51,14 @@ public static <K, V> MMap<K, V> copy(MMap<K, V> orig) {
5251
}
5352

5453
public static <K, V> MMap<K, Collection<V>> copyWithListValue(MMap<K, Collection<V>> orig) {
55-
HashMap<K, Collection<V>> newMap = new HashMap<>((int) Math.ceil(orig.size() / 0.75D));
56-
for (Map.Entry<K, Collection<V>> entry : orig.delegate.entrySet()) {
54+
HashMap<K, Collection<V>> delegateLocal = orig.delegate;
55+
HashMap<K, Collection<V>> newMap = new HashMap<>((int) Math.ceil(delegateLocal.size() / 0.75D));
56+
for (Map.Entry<K, Collection<V>> entry : delegateLocal.entrySet()) {
5757
newMap.put(entry.getKey(), entry.getValue() == null ? null : new ArrayList<>(entry.getValue()));
5858
}
5959
return new MMap<>(newMap);
6060
}
6161

62-
public static <K, V> MMap<K, V> append(MMap<K, V> orig) {
63-
return new AppendMMap<>(orig);
64-
}
65-
6662
protected final HashMap<K, V> delegate;
6763

6864
private MMap(HashMap<K, V> delegate) {
@@ -85,10 +81,6 @@ public MMap<K, V> done() {
8581
return new DoneMMap<>(delegate);
8682
}
8783

88-
public MMap<K, V> append() {
89-
return new AppendMMap<>(this);
90-
}
91-
9284
@Override
9385
public int hashCode() {
9486
throw new IllegalStateException("MMap is not done yet");
@@ -99,20 +91,16 @@ public boolean equals(Object o) {
9991
throw new IllegalStateException("MMap is not done yet");
10092
}
10193

102-
public int size() {
94+
protected int size() {
10395
return delegate.size();
10496
}
10597

10698
private static class DoneMMap<K, V> extends MMap<K, V> {
107-
volatile long hashCode = Long.MAX_VALUE;
99+
private final int hashCode;
108100

109101
private DoneMMap(HashMap<K, V> delegate) {
110102
super(delegate);
111-
}
112-
113-
private DoneMMap(HashMap<K, V> delegate, long hashCode) {
114-
super(delegate);
115-
this.hashCode = hashCode;
103+
this.hashCode = delegate.hashCode();
116104
}
117105

118106
@Override
@@ -127,12 +115,7 @@ public MMap<K, V> done() {
127115

128116
@Override
129117
public int hashCode() {
130-
if (this.hashCode != Long.MAX_VALUE) {
131-
return (int) hashCode;
132-
}
133-
int result = delegate.hashCode();
134-
this.hashCode = result;
135-
return result;
118+
return hashCode;
136119
}
137120

138121
@Override
@@ -144,35 +127,4 @@ public boolean equals(Object o) {
144127
return delegate.equals(other.delegate);
145128
}
146129
}
147-
148-
private static class AppendMMap<K, V> extends DoneMMap<K, V> {
149-
150-
AppendMMap(MMap<K, V> orig) {
151-
super(new HashMap<>(orig.delegate));
152-
if (orig instanceof DoneMMap) {
153-
this.hashCode = ((DoneMMap<K, V>) orig).hashCode;
154-
} else {
155-
this.hashCode = Long.MAX_VALUE;
156-
}
157-
}
158-
159-
@Override
160-
public V put(K key, V value) {
161-
boolean ifPresent = delegate.containsKey(key);
162-
V originalValue = delegate.put(key, value);
163-
if (hashCode != Long.MAX_VALUE) {
164-
int keyHash = Objects.hashCode(key);
165-
if (ifPresent) {
166-
hashCode -= keyHash ^ Objects.hashCode(originalValue);
167-
}
168-
hashCode += keyHash ^ Objects.hashCode(value);
169-
}
170-
return originalValue;
171-
}
172-
173-
@Override
174-
public MMap<K, V> done() {
175-
return new DoneMMap<>(delegate, hashCode);
176-
}
177-
}
178130
}

0 commit comments

Comments
 (0)