Copilot commented on code in PR #2629:
URL: https://github.com/apache/karaf/pull/2629#discussion_r3176791716
##########
tooling/utils/src/main/java/org/apache/karaf/tools/utils/SortedProperties.java:
##########
@@ -40,28 +40,13 @@ public Set<Object> keySet() {
@Override
public Set<Map.Entry<Object, Object>> entrySet() {
- Set<Map.Entry<Object, Object>> origSet = super.entrySet();
- Set<Map.Entry<Object, Object>> sortedSet = new
LinkedHashSet<Map.Entry<Object, Object>>(origSet.size());
-
- Iterator<Map.Entry<Object, Object>> iterator =
origSet.stream().sorted(new Comparator<Map.Entry<Object, Object>>() {
-
- @Override
- public int compare(java.util.Map.Entry<Object, Object> o1,
java.util.Map.Entry<Object, Object> o2) {
- return
o1.getKey().toString().compareTo(o2.getKey().toString());
- }
- }).iterator();
-
- while (iterator.hasNext())
- sortedSet.add(iterator.next());
-
- return sortedSet;
+ return super.entrySet().stream()
+ .sorted(Comparator.comparing(entry -> entry.getKey().toString()))
+ .collect(Collectors.toCollection(LinkedHashSet::new));
Review Comment:
Potential small performance regression: the previous implementation
pre-sized the LinkedHashSet to `origSet.size()` to avoid rehashing as entries
are added. With `Collectors.toCollection(LinkedHashSet::new)`, the set starts
at default capacity (16) and may resize for larger property files. Consider
collecting into a pre-sized LinkedHashSet (e.g., by capturing
`super.entrySet()` size first and using a supplier that creates `new
LinkedHashSet<>(size)`), if this is on a hot path / large properties are
expected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]