eolivelli commented on a change in pull request #1306: ZOOKEEPER-3415: Convert
internal logic to use streams
URL: https://github.com/apache/zookeeper/pull/1306#discussion_r403723175
##########
File path:
zookeeper-server/src/main/java/org/apache/zookeeper/JLineZNodeCompleter.java
##########
@@ -65,11 +67,8 @@ private int completeZNode(String buffer, String token,
List<String> candidates)
// Only the root path can end in a /, so strip it off every other
prefix
String dir = idx == 1 ? "/" : path.substring(0, idx - 1);
List<String> children = zk.getChildren(dir, false);
- for (String child : children) {
- if (child.startsWith(prefix)) {
- candidates.add(child);
- }
- }
+ candidates = children.stream().filter(child ->
child.startsWith(prefix)).collect(Collectors.toList());
Review comment:
Personally I don't find a real benefit and code actually doesn't look better.
Why do you want to change this loop?
It is actually using more resources than the fore each loop.
This is not an hot path but the question is more general.
Streams look appealing but sometimes the overhead is not worth
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services