Skip to content

Commit 975526f

Browse files
committed
Check port equality first in BoltServerAddress
Because it is faster to check port integers and only then check host strings.
1 parent 4707140 commit 975526f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

driver/src/main/java/org/neo4j/driver/internal/BoltServerAddress.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.net.UnknownHostException;
2626

2727
import static java.lang.String.format;
28+
import static java.util.Objects.requireNonNull;
2829

2930
/**
3031
* Holds a host and port pair that denotes a Bolt server address.
@@ -49,23 +50,23 @@ public BoltServerAddress( URI uri )
4950

5051
public BoltServerAddress( String host, int port )
5152
{
52-
this.host = host;
53+
this.host = requireNonNull( host );
5354
this.port = port;
5455
}
5556

5657
@Override
57-
public boolean equals( Object obj )
58+
public boolean equals( Object o )
5859
{
59-
if ( this == obj )
60+
if ( this == o )
6061
{
6162
return true;
6263
}
63-
if ( !(obj instanceof BoltServerAddress) )
64+
if ( o == null || getClass() != o.getClass() )
6465
{
6566
return false;
6667
}
67-
BoltServerAddress address = (BoltServerAddress) obj;
68-
return host.equals( address.host ) && port == address.port;
68+
BoltServerAddress that = (BoltServerAddress) o;
69+
return port == that.port && host.equals( that.host );
6970
}
7071

7172
@Override

0 commit comments

Comments
 (0)