enixon commented on a change in pull request #870: ZOOKEEPER-3335: Prefer 
ArrayList over LinkedList
URL: https://github.com/apache/zookeeper/pull/870#discussion_r269365587
 
 

 ##########
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/ZKDatabase.java
 ##########
 @@ -187,18 +190,21 @@ public ReentrantReadWriteLock getLogLock() {
     }
 
 
-    public synchronized List<Proposal> getCommittedLog() {
+    public synchronized Collection<Proposal> getCommittedLog() {
+        final Collection<Proposal> result;
         ReadLock rl = logLock.readLock();
-        // only make a copy if this thread isn't already holding a lock
-        if(logLock.getReadHoldCount() <=0) {
+        // make a copy if this thread is not already holding a lock
+        if (logLock.getReadHoldCount() > 0) {
+          result = this.committedLog;
+        } else {
+            rl.lock();
             try {
-                rl.lock();
-                return new LinkedList<Proposal>(this.committedLog);
+                result = new ArrayList<>(this.committedLog);
             } finally {
                 rl.unlock();
             }
         }
-        return this.committedLog;
+        return Collections.unmodifiableCollection(result);
 
 Review comment:
   For other reviewers - the changes here are the most interesting (imo).

----------------------------------------------------------------
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

Reply via email to