Changeset 0ec77f5


Ignore:
Timestamp:
Nov 23, 2012 7:22:58 AM (8 years ago)
Author:
zab <zab@…>
Branches:
master
Children:
55c2649
Parents:
f238d05
Message:

Use the cached iterator list to remove Iterator allocation hotspots

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/RouterInfo.java

    rf238d05 r0ec77f5  
    1616import java.security.DigestInputStream;
    1717import java.security.MessageDigest;
    18 import java.util.ArrayList;
    1918import java.util.Collection;
    2019import java.util.Collections;
     
    3231import net.i2p.crypto.SHA1Hash;
    3332import net.i2p.crypto.SHA256Generator;
     33import net.i2p.util.CachedIteratorArrayList;
    3434import net.i2p.util.Clock;
    3535import net.i2p.util.Log;
     
    8282   
    8383    public RouterInfo() {
    84         _addresses = new ArrayList(2);
     84        _addresses = new CachedIteratorArrayList<RouterAddress>(2);
    8585        _options = new OrderedProperties();
    8686    }
  • core/java/test/junit/net/i2p/util/CachedIteratorArrayListTest.java

    rf238d05 r0ec77f5  
    33import static org.junit.Assert.*;
    44
     5import java.util.Collections;
    56import java.util.Iterator;
    67import java.util.List;
     
    6970        assertFalse(iter.hasNext());
    7071    }
     72   
     73    /**
     74     * tests the Collections.sort method because that is used
     75     * in the router and internally creates iterators
     76     */
     77    @Test
     78    public void testSorting() {
     79        List<Integer> li = new CachedIteratorArrayList<Integer>();
     80        li.add(3);
     81        li.add(2);
     82        li.add(1);
     83        Collections.sort(li);
     84       
     85        Iterator<Integer> ii = li.iterator();
     86        assertEquals(1,ii.next().intValue());
     87        assertEquals(2,ii.next().intValue());
     88        assertEquals(3,ii.next().intValue());
     89       
     90        assertFalse(ii.hasNext());
     91    }
    7192}
  • router/java/src/net/i2p/router/transport/udp/PeerState.java

    rf238d05 r0ec77f5  
    1919import net.i2p.router.util.CoDelPriorityBlockingQueue;
    2020import net.i2p.router.util.PriBlockingQueue;
     21import net.i2p.util.CachedIteratorArrayList;
    2122import net.i2p.util.Log;
    2223import net.i2p.util.ConcurrentHashSet;
     
    324325        _rttDeviation = _rtt;
    325326        _inboundMessages = new HashMap(8);
    326         _outboundMessages = new ArrayList(32);
     327        _outboundMessages = new CachedIteratorArrayList<OutboundMessageState>(32);
    327328        //_outboundQueue = new CoDelPriorityBlockingQueue(ctx, "UDP-PeerState", 32);
    328329        _outboundQueue = new PriBlockingQueue(ctx, "UDP-PeerState", 32);
Note: See TracChangeset for help on using the changeset viewer.