Skip to content

Commit 1d8e5f4

Browse files
committed
Revert to Map entry iteration for less expensive static initialization
Issue: SPR-17169 (cherry picked from commit df51ff0)
1 parent d8aecd8 commit 1d8e5f4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: spring-core/src/main/java/org/springframework/util/ClassUtils.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ public abstract class ClassUtils {
121121
primitiveWrapperTypeMap.put(Long.class, long.class);
122122
primitiveWrapperTypeMap.put(Short.class, short.class);
123123

124-
primitiveWrapperTypeMap.forEach((key, value) -> {
125-
primitiveTypeToWrapperMap.put(value, key);
126-
registerCommonClasses(key);
127-
});
124+
// Map entry iteration is less expensive to initialize than forEach with lambdas
125+
for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
126+
primitiveTypeToWrapperMap.put(entry.getValue(), entry.getKey());
127+
registerCommonClasses(entry.getKey());
128+
}
128129

129130
Set<Class<?>> primitiveTypes = new HashSet<>(32);
130131
primitiveTypes.addAll(primitiveWrapperTypeMap.values());

0 commit comments

Comments
 (0)