Skip to content

Commit 7fcbc86

Browse files
wizard4wusbrannen
authored andcommitted
Specify initial capacity when creating ArrayList in SpringFactoriesLoader
Closes gh-30271
1 parent 4eed2ce commit 7fcbc86

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -341,8 +341,9 @@ protected static Map<String, List<String>> loadFactoriesResource(ClassLoader cla
341341
UrlResource resource = new UrlResource(urls.nextElement());
342342
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
343343
properties.forEach((name, value) -> {
344-
List<String> implementations = result.computeIfAbsent(((String) name).trim(), key -> new ArrayList<>());
345-
Arrays.stream(StringUtils.commaDelimitedListToStringArray((String) value))
344+
String[] factoryImplementationNames= StringUtils.commaDelimitedListToStringArray((String) value);
345+
List<String> implementations = result.computeIfAbsent(((String) name).trim(), key -> new ArrayList<>(factoryImplementationNames.length));
346+
Arrays.stream(factoryImplementationNames)
346347
.map(String::trim).forEach(implementations::add);
347348
});
348349
}

0 commit comments

Comments
 (0)