Skip to content
Permalink
Browse files

Optimize toArray (#1395) (#1396)

* Optimize toArray (#1395)

replace toArray(new T[size]) with toArray(new T[0]) for better performance

* Optimize toArray (#1395)

replace toArray(new T[size]) with toArray(new T[0]) for better performance

https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_conclusion (also contains benchmarks).
  • Loading branch information...
hc-codersatlas authored and davecramer committed Jan 29, 2019
1 parent ef14cea commit 2341623b43bf2c9b1b24f41e7ec2eb37acaa6a62
@@ -201,7 +201,7 @@ public synchronized void addNotification(PGNotification notification) {

@Override
public synchronized PGNotification[] getNotifications() throws SQLException {
PGNotification[] array = notifications.toArray(new PGNotification[notifications.size()]);
PGNotification[] array = notifications.toArray(new PGNotification[0]);
notifications.clear();
return array;
}
@@ -163,7 +163,7 @@ void fireConnectionClosed() {
ConnectionEvent evt = null;
// Copy the listener list so the listener can remove itself during this method call
ConnectionEventListener[] local =
listeners.toArray(new ConnectionEventListener[listeners.size()]);
listeners.toArray(new ConnectionEventListener[0]);
for (ConnectionEventListener listener : local) {
if (evt == null) {
evt = createConnectionEvent(null);
@@ -179,7 +179,7 @@ void fireConnectionFatalError(SQLException e) {
ConnectionEvent evt = null;
// Copy the listener list so the listener can remove itself during this method call
ConnectionEventListener[] local =
listeners.toArray(new ConnectionEventListener[listeners.size()]);
listeners.toArray(new ConnectionEventListener[0]);
for (ConnectionEventListener listener : local) {
if (evt == null) {
evt = createConnectionEvent(e);
@@ -148,7 +148,7 @@ public String chooseServerAlias(String keyType, Principal[] issuers, Socket sock
certfile), PSQLState.CONNECTION_FAILURE, gsex);
return null;
}
cert = certs.toArray(new X509Certificate[certs.size()]);
cert = certs.toArray(new X509Certificate[0]);
}
return cert;
}
@@ -408,7 +408,7 @@ public int prepare(Xid xid) throws XAException {
}
rs.close();

return l.toArray(new Xid[l.size()]);
return l.toArray(new Xid[0]);
} finally {
stmt.close();
}

0 comments on commit 2341623

Please sign in to comment.
You can’t perform that action at this time.