Integer.valueOf() is cheaper than new Integer()

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@722083 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2008-12-01 14:36:31 +00:00
parent b2902f1ca0
commit 2d66adf715
2 changed files with 31 additions and 31 deletions

View File

@ -223,14 +223,14 @@ public class TestHttpRoute extends TestCase {
// we can't test hashCode in general due to it's dependency
// on InetAddress and HttpHost, but we can check for the flags
Set<Integer> routecodes = new HashSet<Integer>();
routecodes.add(new Integer(routefff.hashCode()));
routecodes.add(new Integer(routefft.hashCode()));
routecodes.add(new Integer(routeftf.hashCode()));
routecodes.add(new Integer(routeftt.hashCode()));
routecodes.add(new Integer(routetff.hashCode()));
routecodes.add(new Integer(routetft.hashCode()));
routecodes.add(new Integer(routettf.hashCode()));
routecodes.add(new Integer(routettt.hashCode()));
routecodes.add(Integer.valueOf(routefff.hashCode()));
routecodes.add(Integer.valueOf(routefft.hashCode()));
routecodes.add(Integer.valueOf(routeftf.hashCode()));
routecodes.add(Integer.valueOf(routeftt.hashCode()));
routecodes.add(Integer.valueOf(routetff.hashCode()));
routecodes.add(Integer.valueOf(routetft.hashCode()));
routecodes.add(Integer.valueOf(routettf.hashCode()));
routecodes.add(Integer.valueOf(routettt.hashCode()));
assertEquals("some flagged routes have same hashCode",
8, routecodes.size());

View File

@ -436,19 +436,19 @@ public class TestRouteTracker extends TestCase {
assertTrue(hs.add(rt4));
assertTrue(hs.add(rt6));
assertTrue(hc0.add(new Integer(rt0.hashCode())));
assertTrue(hc4.add(new Integer(rt4.hashCode())));
assertTrue(hc6.add(new Integer(rt6.hashCode())));
assertTrue(hc0.add(Integer.valueOf(rt0.hashCode())));
assertTrue(hc4.add(Integer.valueOf(rt4.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt6.hashCode())));
rt = (RouteTracker) rt0.clone();
rt.connectTarget(false);
assertTrue(hs.add(rt));
assertTrue(hc0.add(new Integer(rt.hashCode())));
assertTrue(hc0.add(Integer.valueOf(rt.hashCode())));
rt = (RouteTracker) rt0.clone();
rt.connectTarget(true);
assertTrue(hs.add(rt));
assertTrue(hc0.add(new Integer(rt.hashCode())));
assertTrue(hc0.add(Integer.valueOf(rt.hashCode())));
// proxy (insecure) -> tunnel (insecure) -> layer (secure)
@ -456,15 +456,15 @@ public class TestRouteTracker extends TestCase {
rt.connectProxy(PROXY1, false);
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc4.add(new Integer(rt.hashCode())));
assertTrue(hc4.add(Integer.valueOf(rt.hashCode())));
rt.tunnelTarget(false);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
assertTrue(hc4.add(Integer.valueOf(rt.hashCode())));
rt.layerProtocol(true);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
assertTrue(hc4.add(Integer.valueOf(rt.hashCode())));
// proxy (secure) -> tunnel (secure) -> layer (insecure)
@ -472,15 +472,15 @@ public class TestRouteTracker extends TestCase {
rt.connectProxy(PROXY1, true);
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc4.add(new Integer(rt.hashCode())));
assertTrue(hc4.add(Integer.valueOf(rt.hashCode())));
rt.tunnelTarget(true);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
assertTrue(hc4.add(Integer.valueOf(rt.hashCode())));
rt.layerProtocol(false);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc4.add(new Integer(rt.hashCode())));
assertTrue(hc4.add(Integer.valueOf(rt.hashCode())));
// PROXY1/i -> PROXY2/i -> tunnel/i -> layer/s
@ -488,20 +488,20 @@ public class TestRouteTracker extends TestCase {
rt.connectProxy(PROXY1, false);
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.tunnelProxy(PROXY2, false);
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.tunnelTarget(false);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.layerProtocol(true);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
// PROXY1/s -> PROXY2/s -> tunnel/s -> layer/i
@ -509,20 +509,20 @@ public class TestRouteTracker extends TestCase {
rt.connectProxy(PROXY1, true);
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.tunnelProxy(PROXY2, true);
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.tunnelTarget(true);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.layerProtocol(false);
assertTrue(hs.add((RouteTracker) rt.clone()));
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
// PROXY2/i -> PROXY1/i -> tunnel/i -> layer/s
@ -530,22 +530,22 @@ public class TestRouteTracker extends TestCase {
rt.connectProxy(PROXY2, false);
assertTrue(hs.add((RouteTracker) rt.clone()));
// this is not guaranteed to be unique...
assertTrue(hc6.add(new Integer(rt.hashCode())));
assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.tunnelProxy(PROXY1, false);
assertTrue(hs.add((RouteTracker) rt.clone()));
// proxy chain sequence does not affect hashcode, so duplicate:
// assertTrue(hc6.add(new Integer(rt.hashCode())));
// assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.tunnelTarget(false);
assertTrue(hs.add((RouteTracker) rt.clone()));
// proxy chain sequence does not affect hashcode, so duplicate:
// assertTrue(hc6.add(new Integer(rt.hashCode())));
// assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
rt.layerProtocol(true);
assertTrue(hs.add((RouteTracker) rt.clone()));
// proxy chain sequence does not affect hashcode, so duplicate:
// assertTrue(hc6.add(new Integer(rt.hashCode())));
// assertTrue(hc6.add(Integer.valueOf(rt.hashCode())));
// check that all toString are OK and different