-
Enhancement
-
Resolution: Fixed
-
P4
-
5.0
-
beta
-
x86
-
windows_2000
A DESCRIPTION OF THE REQUEST :
When two URLs are compared java.net.URL.equals(Object) delegates the final decision to java.net.URLStreamHandler.equals(URL, URL).
The documentation says that two urls are considered equal when they refer to the same fragment in the same file. In the implementation the references of both URLs are determined first and stored in two Strings.
If those are not identical (!= and !equals) the method should return false immediately, because any further comparison of other URLs parts would be superflous. This could be achieved by changing the return statements order from
return sameFile(u1, u2) &&
(ref1 == ref2 ||
(ref1 != null && ref1.equals(ref2)));
to
return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
sameFile(u1, u2);
Moreover the sameFile(URL, URL) method can be sped up, too. Its implementation first compares the protocol parts of the two given URLs and returns false if they do not match.
The next check is "hostsEqual(URL, URL)" which can be very expensive as it may block during name resolution in InetAddress.getByName(String).
It would be better to first compare the filename and port number and return false as soon as any of those fails. If and only if parts of the URL have been identified to be identical in both URLs hostsEqual(URL, URL) should be called.
JUSTIFICATION :
Performance of URL comparisons can be increased (potentially a lot), if unnecessary lookups are prevented.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Faster response time of URLStreamHandler.equals(URL, URL) in case any part of the given URLs differ apart from the host.
ACTUAL -
A call to host lookup is always performed, although not necessary of other parts of the URLs differ, which can be checked much faster.
###@###.### 2004-12-09 22:31:15 GMT
When two URLs are compared java.net.URL.equals(Object) delegates the final decision to java.net.URLStreamHandler.equals(URL, URL).
The documentation says that two urls are considered equal when they refer to the same fragment in the same file. In the implementation the references of both URLs are determined first and stored in two Strings.
If those are not identical (!= and !equals) the method should return false immediately, because any further comparison of other URLs parts would be superflous. This could be achieved by changing the return statements order from
return sameFile(u1, u2) &&
(ref1 == ref2 ||
(ref1 != null && ref1.equals(ref2)));
to
return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
sameFile(u1, u2);
Moreover the sameFile(URL, URL) method can be sped up, too. Its implementation first compares the protocol parts of the two given URLs and returns false if they do not match.
The next check is "hostsEqual(URL, URL)" which can be very expensive as it may block during name resolution in InetAddress.getByName(String).
It would be better to first compare the filename and port number and return false as soon as any of those fails. If and only if parts of the URL have been identified to be identical in both URLs hostsEqual(URL, URL) should be called.
JUSTIFICATION :
Performance of URL comparisons can be increased (potentially a lot), if unnecessary lookups are prevented.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Faster response time of URLStreamHandler.equals(URL, URL) in case any part of the given URLs differ apart from the host.
ACTUAL -
A call to host lookup is always performed, although not necessary of other parts of the URLs differ, which can be checked much faster.
###@###.### 2004-12-09 22:31:15 GMT