diff --git a/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java b/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java
index 57d45041a..7db7c160d 100644
--- a/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java
+++ b/httpclient/src/main/java/org/apache/http/conn/routing/HttpRoute.java
@@ -324,22 +324,23 @@ public final class HttpRoute implements RouteInfo, Cloneable {
/**
* Compares this route to another.
*
- * @param o the object to compare with
+ * @param obj the object to compare with
*
* @return true
if the argument is the same route,
* false
*/
@Override
public final boolean equals(Object obj) {
- if (obj == null) return false;
if (this == obj) return true;
if (obj instanceof HttpRoute) {
HttpRoute that = (HttpRoute) obj;
- return LangUtils.equals(this.targetHost, that.targetHost) &&
- LangUtils.equals(this.localAddress, that.localAddress) &&
+ return
+ // Do the cheapest tests first
(this.secure == that.secure) &&
(this.tunnelled == that.tunnelled) &&
(this.layered == that.layered) &&
+ LangUtils.equals(this.targetHost, that.targetHost) &&
+ LangUtils.equals(this.localAddress, that.localAddress) &&
LangUtils.equals(this.proxyChain, that.proxyChain);
} else {
return false;
diff --git a/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java b/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java
index 32f3f687c..86ada48ba 100644
--- a/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java
+++ b/httpclient/src/main/java/org/apache/http/conn/routing/RouteTracker.java
@@ -30,6 +30,7 @@ package org.apache.http.conn.routing;
import java.net.InetAddress;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.util.LangUtils;
import org.apache.http.HttpHost;
@@ -293,30 +294,15 @@ public final class RouteTracker implements RouteInfo, Cloneable {
return false;
RouteTracker that = (RouteTracker) o;
- boolean equal = this.targetHost.equals(that.targetHost);
- equal &=
- ( this.localAddress == that.localAddress) ||
- ((this.localAddress != null) &&
- this.localAddress.equals(that.localAddress));
- equal &=
- ( this.proxyChain == that.proxyChain) ||
- ((this.proxyChain != null) &&
- (that.proxyChain != null) &&
- (this.proxyChain.length == that.proxyChain.length));
- // comparison of actual proxies follows below
- equal &=
+ return
+ // Do the cheapest checks first
(this.connected == that.connected) &&
(this.secure == that.secure) &&
(this.tunnelled == that.tunnelled) &&
- (this.layered == that.layered);
-
- // chain length has been compared above, now check the proxies
- if (equal && (this.proxyChain != null)) {
- for (int i=0; equal && (i