Skip to content

Commit 885b68e

Browse files
oschwaldclaude
andcommitted
Convert CachedConstructor to record
Converts the internal CachedConstructor class to use Java 17 records, reducing boilerplate and improving memory layout. Updates all getter method calls to use record accessors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d6f7658 commit 885b68e

2 files changed

Lines changed: 10 additions & 37 deletions

File tree

src/main/java/com/maxmind/db/CachedConstructor.java

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,10 @@
33
import java.lang.reflect.Constructor;
44
import java.util.Map;
55

6-
final class CachedConstructor<T> {
7-
private final Constructor<T> constructor;
8-
private final Class<?>[] parameterTypes;
9-
private final java.lang.reflect.Type[] parameterGenericTypes;
10-
private final Map<String, Integer> parameterIndexes;
11-
12-
CachedConstructor(
13-
Constructor<T> constructor,
14-
Class<?>[] parameterTypes,
15-
java.lang.reflect.Type[] parameterGenericTypes,
16-
Map<String, Integer> parameterIndexes
17-
) {
18-
this.constructor = constructor;
19-
this.parameterTypes = parameterTypes;
20-
this.parameterGenericTypes = parameterGenericTypes;
21-
this.parameterIndexes = parameterIndexes;
22-
}
23-
24-
Constructor<T> getConstructor() {
25-
return this.constructor;
26-
}
27-
28-
Class<?>[] getParameterTypes() {
29-
return this.parameterTypes;
30-
}
31-
32-
java.lang.reflect.Type[] getParameterGenericTypes() {
33-
return this.parameterGenericTypes;
34-
}
35-
36-
Map<String, Integer> getParameterIndexes() {
37-
return this.parameterIndexes;
38-
}
6+
record CachedConstructor<T>(
7+
Constructor<T> constructor,
8+
Class<?>[] parameterTypes,
9+
java.lang.reflect.Type[] parameterGenericTypes,
10+
Map<String, Integer> parameterIndexes
11+
) {
3912
}

src/main/java/com/maxmind/db/Decoder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
410410
)
411411
);
412412
} else {
413-
constructor = cachedConstructor.getConstructor();
414-
parameterTypes = cachedConstructor.getParameterTypes();
415-
parameterGenericTypes = cachedConstructor.getParameterGenericTypes();
416-
parameterIndexes = cachedConstructor.getParameterIndexes();
413+
constructor = cachedConstructor.constructor();
414+
parameterTypes = cachedConstructor.parameterTypes();
415+
parameterGenericTypes = cachedConstructor.parameterGenericTypes();
416+
parameterIndexes = cachedConstructor.parameterIndexes();
417417
}
418418

419419
Object[] parameters = new Object[parameterTypes.length];

0 commit comments

Comments
 (0)