Skip to content

Commit 6b506ae

Browse files
committed
Switch inheritance-pair cache to ConversionPair-keyed map
1 parent 6ed440e commit 6b506ae

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* **API CLEANUP**: Consolidated internal one-arg simple-type call sites to the 2-arg form and removed associated one-arg cache plumbing in `Converter` to reduce API surface and maintenance complexity.
2525
* **COMPATIBILITY**: Reintroduced one-arg `isSimpleTypeConversionSupported(Class<?>)` as `@Deprecated` compatibility bridges (delegating to `isSimpleTypeConversionSupported(type, type)`) so projects pinned to older `json-io` binaries continue to run during migration.
2626
* **REFACTOR**: Simplified `isSimpleTypeConversionSupported(source, target)` implementation into a thin semantic gate over `isConversionSupportedFor(source, target)` while preserving custom-override and container exclusion behavior.
27+
* **PERFORMANCE**: `Converter` inheritance-pair cache now uses `Map<ConversionPair, InheritancePair[]>` keyed directly by `(sourceType, targetType)` instead of `MultiKeyMap`, reducing cache key construction overhead in conversion-support lookups.
2728
* **MAINTENANCE**: Verified `Converter.isConversionSupportedFor(source, target)` as the compatibility predicate for json-io scalar fast-path converter gating, enabling downstream simplification away from pair-form "simple type" checks while preserving conversion behavior.
2829
* **MAINTENANCE**: Version bump to 4.94.0, json-io test dependency updated to 4.93.0.
2930

src/main/java/com/cedarsoftware/util/convert/Converter.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import com.cedarsoftware.util.ClassUtilities;
6464
import com.cedarsoftware.util.ClassValueMap;
6565
import com.cedarsoftware.util.IdentitySet;
66-
import com.cedarsoftware.util.MultiKeyMap;
6766
import com.cedarsoftware.util.geom.Color;
6867
import com.cedarsoftware.util.geom.Dimension;
6968
import com.cedarsoftware.util.geom.Insets;
@@ -204,10 +203,7 @@ public final class Converter {
204203
public static final String PRECISION_NANOS = "nanos";
205204
private static final Map<Class<?>, SortedSet<ClassLevel>> cacheParentTypes = new ClassValueMap<>();
206205
private static final Map<Class<?>, SortedSet<ClassLevel>> cacheCompleteHierarchy = new ClassValueMap<>();
207-
private static final MultiKeyMap<InheritancePair[]> cacheInheritancePairs = MultiKeyMap.<InheritancePair[]>builder()
208-
.flattenDimensions(true)
209-
.collectionKeyMode(MultiKeyMap.CollectionKeyMode.COLLECTIONS_NOT_EXPANDED)
210-
.build();
206+
private static final Map<ConversionPair, InheritancePair[]> cacheInheritancePairs = new ConcurrentHashMap<>(256, 0.75f);
211207
private static final Map<ConversionPair, Convert<?>> CONVERSION_DB = new ConcurrentHashMap<>(4096, 0.8f);
212208
private final Map<ConversionPair, Convert<?>> USER_DB = new ConcurrentHashMap<>(16, 0.8f);
213209
private static final Map<ConversionPair, Convert<?>> FULL_CONVERSION_CACHE = new ConcurrentHashMap<>(1024, 0.75f);
@@ -1991,7 +1987,7 @@ private static SortedSet<ClassLevel> getCompleteTypeHierarchy(Class<?> clazz) {
19911987
* @return Cached, sorted array of InheritancePair objects
19921988
*/
19931989
private static InheritancePair[] getSortedInheritancePairs(Class<?> sourceType, Class<?> toType) {
1994-
Object[] key = {sourceType, toType};
1990+
ConversionPair key = pair(sourceType, toType, 0L);
19951991
InheritancePair[] cached = cacheInheritancePairs.get(key);
19961992
if (cached != null) {
19971993
return cached;
@@ -2047,8 +2043,8 @@ private static InheritancePair[] getSortedInheritancePairs(Class<?> sourceType,
20472043
});
20482044

20492045
InheritancePair[] pairsArray = pairs.toArray(new InheritancePair[0]);
2050-
cacheInheritancePairs.putMultiKey(pairsArray, sourceType, toType);
2051-
return pairsArray;
2046+
InheritancePair[] existing = cacheInheritancePairs.putIfAbsent(key, pairsArray);
2047+
return existing != null ? existing : pairsArray;
20522048
}
20532049

20542050
/**

0 commit comments

Comments
 (0)