You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2019/08/25 18:19:25 UTC

[GitHub] [accumulo] belugabehr commented on a change in pull request #1333: Removed LinkedList from CachedBlockQueue in favor of ArrayList

belugabehr commented on a change in pull request #1333: Removed LinkedList from CachedBlockQueue in favor of ArrayList
URL: https://github.com/apache/accumulo/pull/1333#discussion_r317409304
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/CachedBlockQueue.java
 ##########
 @@ -91,24 +93,19 @@ public void add(CachedBlock cb) {
    * @return list of cached elements in descending order
    */
   public CachedBlock[] get() {
-    LinkedList<CachedBlock> blocks = new LinkedList<>();
-    while (!queue.isEmpty()) {
-      blocks.addFirst(queue.poll());
-    }
-    return blocks.toArray(new CachedBlock[blocks.size()]);
+     CachedBlock[] blocks = queue.toArray(new CachedBlock[0]);
 
 Review comment:
   Thanks for the review @ctubbsii ! This is the correct way to call `toArray()`.
   
   Check out the example here:
   
   https://docs.oracle.com/javase/8/docs/api/?java/util/Collections.html
   
   >Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, *a new array is allocated* with the runtime type of the specified array and the size of this collection.
   
   The `new CachedBlock[0]` is a no-op since an array of size zero cannot be resized and cannot contain any elements, therefore, it is completely immutable.  The compiler will just create a single global instance of the empty array.  It does not create a new empty array for each invocation at runtime.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services