BELUGABEHR commented on a change in pull request #870: ZOOKEEPER-3335: Prefer
ArrayList over LinkedList
URL: https://github.com/apache/zookeeper/pull/870#discussion_r269381357
##########
File path:
zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/CommitProcessor.java
##########
@@ -200,13 +202,9 @@ public void run() {
if (needCommit(request)
|| pendingRequests.containsKey(request.sessionId))
{
// Add request to pending
- LinkedList<Request> requests = pendingRequests
- .get(request.sessionId);
- if (requests == null) {
- requests = new LinkedList<Request>();
- pendingRequests.put(request.sessionId, requests);
- }
- requests.addLast(request);
+ pendingRequests
+ .computeIfAbsent(request.sessionId, sid -> new
ArrayDeque<>())
+ .add(request);
Review comment:
FYI. This is exactly how this is intended to be used:
https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#computeIfAbsent-K-java.util.function.Function-
----------------------------------------------------------------
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