commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1346705 - /commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/util/SingleLinkedList.java
Date Wed, 06 Jun 2012 02:03:47 GMT
Author: dblevins
Date: Wed Jun  6 02:03:46 2012
New Revision: 1346705

URL: http://svn.apache.org/viewvc?rev=1346705&view=rev
Log:
Some history on why this list implementation exists

Modified:
    commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/util/SingleLinkedList.java

Modified: commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/util/SingleLinkedList.java
URL: http://svn.apache.org/viewvc/commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/util/SingleLinkedList.java?rev=1346705&r1=1346704&r2=1346705&view=diff
==============================================================================
--- commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/util/SingleLinkedList.java
(original)
+++ commons/sandbox/classscan/branches/commons-finder/src/main/java/org/apache/commons/classscan/finder/util/SingleLinkedList.java
Wed Jun  6 02:03:46 2012
@@ -23,6 +23,36 @@ import java.util.List;
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
 
+/**
+ * Arraylist was initially used to hold class metadata, this proved wasteful
+ *
+ * This metadata is typically list of parameters, list of interfaces,
+ * list of methods, list of constructors, list of fields, and of course
+ * list of annotations.
+ *
+ * ArrayList defaults to 10 entries.  A basic ClassInfo would therefore
+ * take a minimum of 50 x 64 bits of just array addressing for even an
+ * empty object with no fields, methods, constructors, interfaces or
+ * annotations.
+ *
+ * Every added field or method would incur another 10 x 64 bits of array
+ * space.  Each method would incur another 10 x 64 bits for the params list
+ * and 10 x 64 bits for the annotations list for each param.
+ *
+ * Using a linked list cuts that down to fractions of the addressing space.
+ * The built-in VM LinkedList is a doubly linked list.
+ *
+ * Using a singly linked list cuts that address space down to half of
+ * that required for a doubly linked list.
+ *
+ * This works out fine as the code in question only adds elements in an
+ * unordered fashion and all iteration is forward only.
+ *
+ * So while this list implementation is not complete, it saves
+ * significantly on memory by cutting down on unused address space.
+ *
+ * @param <E>
+ */
 public class SingleLinkedList<E> implements List<E> {
 
     private Entry<E> entry;
@@ -90,6 +120,14 @@ public class SingleLinkedList<E> impleme
         return true;
     }
 
+    public boolean addAll(Collection<? extends E> c) {
+        for (E e : c) {
+            add(e);
+        }
+
+        return true;
+    }
+
     public boolean remove(Object o) {
         throw new UnsupportedOperationException("remove");
     }
@@ -98,10 +136,6 @@ public class SingleLinkedList<E> impleme
         throw new UnsupportedOperationException("containsAll");
     }
 
-    public boolean addAll(Collection<? extends E> c) {
-        throw new UnsupportedOperationException("addAll");
-    }
-
     public boolean addAll(int index, Collection<? extends E> c) {
         throw new UnsupportedOperationException("addAll");
     }



Mime
View raw message