java.util.LinkedList clear() improvement

Tom Hawtin Thomas.Hawtin at Sun.COM
Thu Aug 27 13:37:50 UTC 2009


Guy Korland wrote:

> It seems like linkedList.clear() can be easily fixed to O(1) instead of O(n).

The code is like that on purpose(!). It was done to help GC, in mustang 
IIRC. There really isn't a problem with clear() being O(n) - it's going 
to take at least O(n) to populate it, and in reality *many* times more 
cycles.

Tom



More information about the core-libs-dev mailing list