Skip to content

Commit

Permalink
Collection initialization/sizing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored and clebertsuconic committed Feb 10, 2014
1 parent d63d01d commit 68989b3
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private static byte[] findFirstMatchingHardwareAddress(List<NetworkInterface> if
final Method isVirtualMethod)
{
ExecutorService executor = Executors.newFixedThreadPool(ifaces.size());
Collection<Callable<byte[]>> tasks = new ArrayList<Callable<byte[]>>();
Collection<Callable<byte[]>> tasks = new ArrayList<Callable<byte[]>>(ifaces.size());

for (final NetworkInterface networkInterface : ifaces)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ public String getName()

public synchronized List<DiscoveryEntry> getDiscoveryEntries()
{
List<DiscoveryEntry> list = new ArrayList<DiscoveryEntry>();

list.addAll(connectors.values());
List<DiscoveryEntry> list = new ArrayList<DiscoveryEntry>(connectors.values());

return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Set<Role> createSecurity(String sendRoles, String consumeRoles, St
allRoles.addAll(consume);
allRoles.addAll(manage);

Set<Role> roles = new HashSet<Role>();
Set<Role> roles = new HashSet<Role>(allRoles.size());
for (String role : allRoles)
{
roles.add(new Role(role,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public JSONArray(final Collection collection)

public JSONArray(final Collection collection, final boolean includeSuperClass)
{
myArrayList = new ArrayList<Object>();
myArrayList = collection == null ? new ArrayList<Object>() : new ArrayList<Object>(collection.size());
if (collection != null)
{
Iterator<Object> iter = collection.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,10 @@ public Set<String> getPropertyNames()
{
try
{
Set<String> propNames = new HashSet<String>();
Set<SimpleString> simplePropNames = properties.getPropertyNames();
Set<String> propNames = new HashSet<String>(simplePropNames.size());

for (SimpleString str : properties.getPropertyNames())
for (SimpleString str : simplePropNames)
{
propNames.add(str.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ public Object getObject(final String name) throws JMSException

public Enumeration getMapNames() throws JMSException
{
Set<String> propNames = new HashSet<String>();
Set<SimpleString> simplePropNames = map.getPropertyNames();
Set<String> propNames = new HashSet<String>(simplePropNames.size());

for (SimpleString str : map.getPropertyNames())
for (SimpleString str : simplePropNames)
{
propNames.add(str.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public JMSJournalStorageManagerImpl(final IDGenerator idGenerator,
@Override
public List<PersistedConnectionFactory> recoverConnectionFactories()
{
List<PersistedConnectionFactory> cfs = new ArrayList<PersistedConnectionFactory>(mapFactories.size());
cfs.addAll(mapFactories.values());
List<PersistedConnectionFactory> cfs = new ArrayList<PersistedConnectionFactory>(mapFactories.values());
return cfs;
}

Expand All @@ -149,8 +148,7 @@ public void deleteConnectionFactory(final String cfName) throws Exception
@Override
public List<PersistedDestination> recoverDestinations()
{
List<PersistedDestination> destinations = new ArrayList<PersistedDestination>(this.destinations.size());
destinations.addAll(this.destinations.values());
List<PersistedDestination> destinations = new ArrayList<PersistedDestination>(this.destinations.values());
return destinations;
}

Expand All @@ -166,10 +164,7 @@ public void storeDestination(final PersistedDestination destination) throws Exce

public List<PersistedJNDI> recoverPersistedJNDI() throws Exception
{
ArrayList<PersistedJNDI> list = new ArrayList<PersistedJNDI>();

list.addAll(mapJNDI.values());

ArrayList<PersistedJNDI> list = new ArrayList<PersistedJNDI>(mapJNDI.values());
return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ public void negotiateVersion(StompFrame frame) throws HornetQStompException
}
else
{
Set<String> requestVersions = new HashSet<String>();
StringTokenizer tokenizer = new StringTokenizer(acceptVersion, ",");
Set<String> requestVersions = new HashSet<String>(tokenizer.countTokens());
while (tokenizer.hasMoreTokens())
{
requestVersions.add(tokenizer.nextToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public FilePushStore(String dirname) throws Exception

public synchronized List<PushRegistration> getRegistrations()
{
List<PushRegistration> list = new ArrayList<PushRegistration>();
list.addAll(map.values());
List<PushRegistration> list = new ArrayList<PushRegistration>(map.values());
return list;
}

Expand Down Expand Up @@ -115,8 +114,7 @@ public synchronized void remove(PushRegistration reg) throws Exception

public synchronized void removeAll() throws Exception
{
ArrayList<PushRegistration> copy = new ArrayList<PushRegistration>();
copy.addAll(map.values());
ArrayList<PushRegistration> copy = new ArrayList<PushRegistration>(map.values());
for (PushRegistration reg : copy) remove(reg);
this.dir.delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ public void cleanup()
*/
private synchronized ArrayList<PageSubscription> cloneSubscriptions()
{
ArrayList<PageSubscription> cursorList = new ArrayList<PageSubscription>();
cursorList.addAll(activeCursors.values());
ArrayList<PageSubscription> cursorList = new ArrayList<PageSubscription>(activeCursors.values());
return cursorList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ protected void cleanup()
return;
}
valueReplace = value.get();
deleteList = new ArrayList<Long>(incrementRecords.size());
deleteList.addAll(incrementRecords);
deleteList = new ArrayList<Long>(incrementRecords);
incrementRecords.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1436,15 +1436,13 @@ public void storeAddressSetting(PersistedAddressSetting addressSetting) throws E

public List<PersistedAddressSetting> recoverAddressSettings() throws Exception
{
ArrayList<PersistedAddressSetting> list = new ArrayList<PersistedAddressSetting>(mapPersistedAddressSettings.size());
list.addAll(mapPersistedAddressSettings.values());
ArrayList<PersistedAddressSetting> list = new ArrayList<PersistedAddressSetting>(mapPersistedAddressSettings.values());
return list;
}

public List<PersistedRoles> recoverPersistedRoles() throws Exception
{
ArrayList<PersistedRoles> list = new ArrayList<PersistedRoles>(mapPersistedRoles.size());
list.addAll(mapPersistedRoles.values());
ArrayList<PersistedRoles> list = new ArrayList<PersistedRoles>(mapPersistedRoles.values());
return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ public RemotingConnection removeConnection(final Object remotingConnectionID)

public synchronized Set<RemotingConnection> getConnections()
{
Set<RemotingConnection> conns = new HashSet<RemotingConnection>();
Set<RemotingConnection> conns = new HashSet<RemotingConnection>(connections.size());

for (ConnectionEntry entry : connections.values())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,7 @@ private void logWarnNoConnector(final String connectorName, final String bgName)

private synchronized Collection<ClusterConnection> cloneClusterConnections()
{
ArrayList<ClusterConnection> list = new ArrayList<ClusterConnection>(clusterConnections.size());
list.addAll(clusterConnections.values());
ArrayList<ClusterConnection> list = new ArrayList<ClusterConnection>(clusterConnections.values());
return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2565,8 +2565,7 @@ private List<ConsumerHolder> cloneConsumersList()

synchronized (this)
{
consumerListClone = new ArrayList<ConsumerHolder>(consumerList.size());
consumerListClone.addAll(consumerList);
consumerListClone = new ArrayList<ConsumerHolder>(consumerList);
}
return consumerListClone;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private List<Match<T>> sort(final Map<String, Match<T>> possibleMatches)
{
List<String> keys = new ArrayList<String>(possibleMatches.keySet());
Collections.sort(keys, matchComparator);
List<Match<T>> matches1 = new ArrayList<Match<T>>();
List<Match<T>> matches1 = new ArrayList<Match<T>>(possibleMatches.size());
for (String key : keys)
{
matches1.add(possibleMatches.get(key));
Expand Down

0 comments on commit 68989b3

Please sign in to comment.