forked from I2P_Developers/i2p.i2p
Use the cached iterator list to remove Iterator allocation hotspots
This commit is contained in:
@ -2,6 +2,7 @@ package net.i2p.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -68,4 +69,24 @@ public class CachedIteratorArrayListTest {
|
||||
assertEquals('c',iter.next().charValue());
|
||||
assertFalse(iter.hasNext());
|
||||
}
|
||||
|
||||
/**
|
||||
* tests the Collections.sort method because that is used
|
||||
* in the router and internally creates iterators
|
||||
*/
|
||||
@Test
|
||||
public void testSorting() {
|
||||
List<Integer> li = new CachedIteratorArrayList<Integer>();
|
||||
li.add(3);
|
||||
li.add(2);
|
||||
li.add(1);
|
||||
Collections.sort(li);
|
||||
|
||||
Iterator<Integer> ii = li.iterator();
|
||||
assertEquals(1,ii.next().intValue());
|
||||
assertEquals(2,ii.next().intValue());
|
||||
assertEquals(3,ii.next().intValue());
|
||||
|
||||
assertFalse(ii.hasNext());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user