8263561: Re-examine uses of LinkedList

Reviewed-by: redestad
This commit is contained in:
Sergey Tsypanov 2021-08-02 12:50:38 +00:00 committed by Claes Redestad
parent 6a3f8343bc
commit 249d641889
9 changed files with 45 additions and 47 deletions

View File

@ -41,7 +41,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
@ -245,7 +244,7 @@ final class ProxyGenerator extends ClassWriter {
* List of return types that are not yet known to be
* assignable from ("covered" by) any of the others.
*/
LinkedList<Class<?>> uncoveredReturnTypes = new LinkedList<>();
List<Class<?>> uncoveredReturnTypes = new ArrayList<>(1);
nextNewReturnType:
for (ProxyMethod pm : methods) {

View File

@ -2888,7 +2888,7 @@ public abstract class ResourceBundle {
if (language.equals("nb") || isNorwegianBokmal) {
List<Locale> tmpList = getDefaultList("nb", script, region, variant);
// Insert a locale replacing "nb" with "no" for every list entry with precedence
List<Locale> bokmalList = new LinkedList<>();
List<Locale> bokmalList = new ArrayList<>();
for (Locale l_nb : tmpList) {
var isRoot = l_nb.getLanguage().isEmpty();
var l_no = Locale.getInstance(isRoot ? "" : "no",
@ -2928,7 +2928,7 @@ public abstract class ResourceBundle {
List<String> variants = null;
if (!variant.isEmpty()) {
variants = new LinkedList<>();
variants = new ArrayList<>();
int idx = variant.length();
while (idx != -1) {
variants.add(variant.substring(0, idx));
@ -2936,7 +2936,7 @@ public abstract class ResourceBundle {
}
}
List<Locale> list = new LinkedList<>();
List<Locale> list = new ArrayList<>();
if (variants != null) {
for (String v : variants) {

View File

@ -54,7 +54,6 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Properties;
@ -219,7 +218,7 @@ public class URLClassPath {
if (closed) {
return Collections.emptyList();
}
List<IOException> result = new LinkedList<>();
List<IOException> result = new ArrayList<>();
for (Loader loader : loaders) {
try {
loader.close();
@ -961,7 +960,7 @@ public class URLClassPath {
Resource res;
String[] jarFiles;
int count = 0;
LinkedList<String> jarFilesList = null;
List<String> jarFilesList;
/* If there no jar files in the index that can potential contain
* this resource then return immediately.

View File

@ -52,13 +52,13 @@ public class JarIndex {
* The hash map that maintains mappings from
* package/classe/resource to jar file list(s)
*/
private HashMap<String,LinkedList<String>> indexMap;
private final HashMap<String, List<String>> indexMap;
/**
* The hash map that maintains mappings from
* jar file to package/class/resource lists
*/
private HashMap<String,LinkedList<String>> jarMap;
private final HashMap<String, List<String>> jarMap;
/*
* An ordered list of jar file names.
@ -132,13 +132,13 @@ public class JarIndex {
/*
* Add the key, value pair to the hashmap, the value will
* be put in a linked list which is created if necessary.
* be put in a list which is created if necessary.
*/
private void addToList(String key, String value,
HashMap<String,LinkedList<String>> t) {
LinkedList<String> list = t.get(key);
HashMap<String, List<String>> t) {
List<String> list = t.get(key);
if (list == null) {
list = new LinkedList<>();
list = new ArrayList<>(1);
list.add(value);
t.put(key, list);
} else if (!list.contains(value)) {
@ -151,8 +151,8 @@ public class JarIndex {
*
* @param fileName the key of the mapping
*/
public LinkedList<String> get(String fileName) {
LinkedList<String> jarFiles = null;
public List<String> get(String fileName) {
List<String> jarFiles;
if ((jarFiles = indexMap.get(fileName)) == null) {
/* try the package name again */
int pos;
@ -166,7 +166,7 @@ public class JarIndex {
/**
* Add the mapping from the specified file to the specified
* jar file. If there were no mapping for the package of the
* specified file before, a new linked list will be created,
* specified file before, a new list will be created,
* the jar file is added to the list and a new mapping from
* the package to the jar file list is added to the hashmap.
* Otherwise, the jar file will be added to the end of the
@ -261,7 +261,7 @@ public class JarIndex {
/* print out the jar file name */
String jar = jarFiles[i];
bw.write(jar + "\n");
LinkedList<String> jarlist = jarMap.get(jar);
List<String> jarlist = jarMap.get(jar);
if (jarlist != null) {
Iterator<String> listitr = jarlist.iterator();
while(listitr.hasNext()) {
@ -320,11 +320,11 @@ public class JarIndex {
*
*/
public void merge(JarIndex toIndex, String path) {
Iterator<Map.Entry<String,LinkedList<String>>> itr = indexMap.entrySet().iterator();
Iterator<Map.Entry<String, List<String>>> itr = indexMap.entrySet().iterator();
while(itr.hasNext()) {
Map.Entry<String,LinkedList<String>> e = itr.next();
Map.Entry<String, List<String>> e = itr.next();
String packageName = e.getKey();
LinkedList<String> from_list = e.getValue();
List<String> from_list = e.getValue();
Iterator<String> listItr = from_list.iterator();
while(listItr.hasNext()) {
String jarName = listItr.next();

View File

@ -30,7 +30,7 @@ import java.net.NetworkInterface;
import java.nio.channels.MembershipKey;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -94,7 +94,7 @@ class MembershipRegistry {
keys = groups.get(group);
}
if (keys == null) {
keys = new LinkedList<>();
keys = new ArrayList<>();
groups.put(group, keys);
}
keys.add(key);

View File

@ -40,14 +40,14 @@ import java.util.*;
abstract class AbstractPoller implements Runnable {
// list of requests pending to the poller thread
private final LinkedList<Request> requestList;
// requests pending to the poller thread
private final ArrayDeque<Request> requests;
// set to true when shutdown
private boolean shutdown;
protected AbstractPoller() {
this.requestList = new LinkedList<>();
this.requests = new ArrayDeque<>();
this.shutdown = false;
}
@ -216,11 +216,11 @@ abstract class AbstractPoller implements Runnable {
private Object invoke(RequestType type, Object... params) throws IOException {
// submit request
Request req = new Request(type, params);
synchronized (requestList) {
synchronized (requests) {
if (shutdown) {
throw new ClosedWatchServiceException();
}
requestList.add(req);
requests.add(req);
// wakeup thread
wakeup();
@ -243,9 +243,9 @@ abstract class AbstractPoller implements Runnable {
*/
@SuppressWarnings("unchecked")
boolean processRequests() {
synchronized (requestList) {
synchronized (requests) {
Request req;
while ((req = requestList.poll()) != null) {
while ((req = requests.poll()) != null) {
// if in process of shutdown then reject request
if (shutdown) {
req.release(new ClosedWatchServiceException());

View File

@ -26,7 +26,7 @@
package sun.util.locale.provider;
import java.lang.ref.SoftReference;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -98,7 +98,7 @@ public final class TimeZoneNameUtility {
// Performs per-ID retrieval.
Set<String> zoneIDs = LocaleProviderAdapter.forJRE().getLocaleResources(locale).getZoneIDs();
List<String[]> zones = new LinkedList<>();
List<String[]> zones = new ArrayList<>();
for (String key : zoneIDs) {
String[] names = retrieveDisplayNamesImpl(key, locale);
if (names != null) {

View File

@ -26,7 +26,7 @@
package sun.net.dns;
import java.util.List;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
@ -56,11 +56,11 @@ public class ResolverConfigurationImpl
// Parse /etc/resolv.conf to get the values for a particular
// keyword.
//
private LinkedList<String> resolvconf(String keyword,
private ArrayList<String> resolvconf(String keyword,
int maxperkeyword,
int maxkeywords)
{
LinkedList<String> ll = new LinkedList<>();
ArrayList<String> ll = new ArrayList<>();
try {
BufferedReader in =
@ -111,8 +111,8 @@ public class ResolverConfigurationImpl
return ll;
}
private LinkedList<String> searchlist;
private LinkedList<String> nameservers;
private ArrayList<String> searchlist;
private ArrayList<String> nameservers;
// Load DNS configuration from OS
@ -133,7 +133,7 @@ public class ResolverConfigurationImpl
nameservers =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public LinkedList<String> run() {
public ArrayList<String> run() {
// typically MAXNS is 3 but we've picked 5 here
// to allow for additional servers if required.
return resolvconf("nameserver", 1, 5);
@ -151,16 +151,16 @@ public class ResolverConfigurationImpl
// obtain search list or local domain
@SuppressWarnings("removal")
private LinkedList<String> getSearchList() {
private ArrayList<String> getSearchList() {
LinkedList<String> sl;
ArrayList<String> sl;
// first try the search keyword in /etc/resolv.conf
sl = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public LinkedList<String> run() {
LinkedList<String> ll;
public ArrayList<String> run() {
ArrayList<String> ll;
// first try search keyword (max 6 domains)
ll = resolvconf("search", 6, 1);
@ -183,8 +183,8 @@ public class ResolverConfigurationImpl
sl = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
public LinkedList<String> run() {
LinkedList<String> ll;
public ArrayList<String> run() {
ArrayList<String> ll;
ll = resolvconf("domain", 1, 1);
if (ll.size() > 0) {
@ -201,7 +201,7 @@ public class ResolverConfigurationImpl
// no local domain so try fallback (RPC) domain or
// hostName
sl = new LinkedList<>();
sl = new ArrayList<>();
String domain = fallbackDomain0();
if (domain != null && !domain.isEmpty()) {
sl.add(domain);

View File

@ -35,7 +35,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
// implementation specific API
@ -64,7 +64,7 @@ public class JarIndexMergeTest {
static void assertFileResolved(JarIndex jarIndex2, String file,
String jarName) {
@SuppressWarnings("unchecked")
LinkedList<String> jarLists = (LinkedList<String>)jarIndex2.get(file);
List<String> jarLists = (List<String>)jarIndex2.get(file);
if (jarLists == null || jarLists.size() == 0 ||
!jarName.equals(jarLists.get(0))) {
throw new RuntimeException(