Skip to content

Commit

Permalink
Change from LinkedList to Arrayist for better performance
Browse files Browse the repository at this point in the history
Fix to #110 Problems with Generator support in Eclipse CMSIS pack manager plugin
  • Loading branch information
Evgueni Driouk committed Oct 27, 2023
1 parent a191e40 commit 0dafd39
Show file tree
Hide file tree
Showing 59 changed files with 274 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

package com.arm.cmsis.config.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

Expand Down Expand Up @@ -47,7 +48,7 @@ public class ConfigWizardItem implements IConfigWizardItem {
private boolean fInvertValue;
private Map<Long, String> fItems;
private Map<String, String> fStrItems;
private LinkedList<IConfigWizardItem> fChildren;
private List<IConfigWizardItem> fChildren;
private String fSelStr;

/**
Expand All @@ -69,7 +70,7 @@ public ConfigWizardItem(EItemType itemType, int line, IConfigWizardItem parent)
fSpinStep = 0;
fItems = new TreeMap<>();
fStrItems = new TreeMap<>();
fChildren = new LinkedList<>();
fChildren = new ArrayList<>();
}

@Override
Expand Down Expand Up @@ -312,10 +313,10 @@ public Collection<IConfigWizardItem> getChildren() {

@Override
public IConfigWizardItem getLastChild() {
if (fChildren == null || fChildren.size() == 0) {
if (fChildren == null || fChildren.isEmpty()) {
return null;
}
return fChildren.getLast();
return fChildren.get(fChildren.size() - 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

package com.arm.cmsis.parser;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -69,7 +69,7 @@ protected boolean removeEldestEntry(Map.Entry<Integer, Boolean> eldest) {

public ConfigWizardScanner(boolean isAsmFile) {
isAsm = isAsmFile;
Collection<IRule> rules = new LinkedList<>();
Collection<IRule> rules = new ArrayList<>();

// Comment rules
rules.add(new CommentRule("//", new Token(CONFIG_COMMENT))); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

package com.arm.cmsis.pack.build.armcc;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.cdt.managedbuilder.core.BuildException;
Expand Down Expand Up @@ -338,7 +338,7 @@ protected Collection<String> getStringListValue(IBuildSettings buildSettings, in
return null;
case ARMCC5_ASMDEFINES_OPTION:
case IBuildSettings.ADEFINES_OPTION: {
List<String> asmDefines = new LinkedList<String>();
List<String> asmDefines = new ArrayList<String>();
if (oType == ARMCC5_ASMDEFINES_OPTION)
oType = IBuildSettings.RTE_DEFINES; // change to key used in buildSettings
Collection<String> defines = buildSettings.getStringListValue(oType);
Expand Down Expand Up @@ -368,7 +368,7 @@ protected Collection<String> getStringListValue(IBuildSettings buildSettings, in
Collection<String> value = super.getStringListValue(buildSettings, oType);
if (rteValue != null && !rteValue.isEmpty()) {
if (value == null) {
value = new LinkedList<>();
value = new ArrayList<>();
}
for (String s : rteValue) {
value.add(CmsisConstants.CMSIS_RTE_VAR + s);
Expand All @@ -382,7 +382,7 @@ protected Collection<String> getRteStringListValue(IBuildSettings buildSettings,
switch (oType) {
case IBuildSettings.ADEFINES_OPTION:
case ARMCC5_ASMDEFINES_OPTION: {
List<String> asmDefines = new LinkedList<String>();
List<String> asmDefines = new ArrayList<String>();
if (oType == ARMCC5_ASMDEFINES_OPTION)
oType = IBuildSettings.RTE_DEFINES; // change to key used in buildSettings
Collection<String> defines = buildSettings.getStringListValue(oType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

package com.arm.cmsis.pack.build.armgcc;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.cdt.managedbuilder.core.BuildException;
Expand Down Expand Up @@ -158,7 +158,7 @@ protected Collection<String> getStringListValue(IBuildSettings buildSettings, in
return null; // we add libraries as objects => ignore libs and lib paths
} else if (type == IBuildSettings.RTE_OBJECTS) {
Collection<String> objs = buildSettings.getStringListValue(IBuildSettings.RTE_OBJECTS);
List<String> value = new LinkedList<String>();
List<String> value = new ArrayList<String>();
if (objs != null && !objs.isEmpty())
value.addAll(objs);
Collection<String> libs = buildSettings.getStringListValue(IBuildSettings.RTE_LIBRARIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

package com.arm.cmsis.pack.build.gnuarmeclipse;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.cdt.managedbuilder.core.IOption;
Expand Down Expand Up @@ -131,7 +131,7 @@ protected Collection<String> getStringListValue(IBuildSettings buildSettings, in
} else if (type == IBuildSettings.RTE_DEFINES) {
// escape defines by adding "${cmsis_rte}" prefix
Collection<String> defines = buildSettings.getStringListValue(IBuildSettings.RTE_DEFINES);
List<String> value = new LinkedList<String>();
List<String> value = new ArrayList<String>();
if (defines != null && !defines.isEmpty()) {
for (String s : defines) {
value.add(CmsisConstants.CMSIS_RTE_VAR + s);
Expand All @@ -141,7 +141,7 @@ protected Collection<String> getStringListValue(IBuildSettings buildSettings, in

} else if (type == IBuildSettings.RTE_OBJECTS) {
Collection<String> objs = buildSettings.getStringListValue(IBuildSettings.RTE_OBJECTS);
List<String> value = new LinkedList<String>();
List<String> value = new ArrayList<String>();
if (objs != null && !objs.isEmpty())
value.addAll(objs);
// add libraries as objects (gcc does not allow to specify libs with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

package com.arm.cmsis.pack.error;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import com.arm.cmsis.pack.common.CmsisConstants;
Expand Down Expand Up @@ -65,7 +65,7 @@ public void addError(CmsisError e) {
if (e == null)
return;
if (fErrors == null)
fErrors = new LinkedList<>();
fErrors = new ArrayList<>();
fErrors.add(e);
ICmsisConsole console = getCmsisConsole();
if (console != null) {
Expand Down Expand Up @@ -99,7 +99,7 @@ public CmsisError getFirstError() {

@Override
public Collection<String> getErrorStrings() {
List<String> errorStrings = new LinkedList<>();
List<String> errorStrings = new ArrayList<>();
for (ICmsisError e : getErrors()) {
errorStrings.add(e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

package com.arm.cmsis.pack.generic;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -49,7 +49,7 @@ public synchronized void removeAllListeners() {
@Override
public synchronized void notifyListeners(E event) {
// make a copy to avoid add/remove conflicts
List<L> workingList = new LinkedList<>(listeners);
List<L> workingList = new ArrayList<>(listeners);
for (Iterator<? extends L> iterator = workingList.iterator(); iterator.hasNext();) {
if (listeners.isEmpty())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;

/**
* Generic template-based interface for tree like structures
Expand Down Expand Up @@ -124,7 +123,7 @@ default <C> Collection<C> getChildrenOfType(Class<C> type) {
if (!hasChildren())
return Collections.emptyList();

LinkedList<C> typedChildren = new LinkedList<>();
ArrayList<C> typedChildren = new ArrayList<>();
for (T child : getChildren()) {
if (type.isInstance(child)) {
typedChildren.add(type.cast(child));
Expand All @@ -141,7 +140,7 @@ default <C> Collection<C> getChildrenOfType(Class<C> type) {
*/
default <C> Collection<C> getAllChildrenOfType(Collection<C> allChildren, Class<C> type) {
if (allChildren == null)
allChildren = new LinkedList<>();
allChildren = new ArrayList<>();
if (hasChildren()) {
allChildren.addAll(getChildrenOfType(type)); // add own
for (T c : getChildren()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

package com.arm.cmsis.pack.item;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -109,7 +109,7 @@ public T findChild(List<String> keyPath, boolean useFullPath) {

@Override
public List<String> getKeyPath() {
List<String> keyPath = new LinkedList<>();
List<String> keyPath = new ArrayList<>();
T child = getThisItem();
for (T parent = getParent(); parent != null; parent = parent.getParent()) {
String key = parent.getItemKey(child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

package com.arm.cmsis.pack.item;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

import com.arm.cmsis.pack.common.CmsisConstants;
import com.arm.cmsis.pack.utils.WildCards;
Expand Down Expand Up @@ -169,7 +169,7 @@ protected Collection<T> children() {
*/
protected Collection<T> createCollection() {
// default creates linkedList
return new LinkedList<>();
return new ArrayList<>();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -167,16 +167,20 @@ public synchronized void registerFile(String file) {
containsWildcards = true;

File f = new File(file);
long modified = 0;
if (f.exists()) {
modified = f.lastModified();
File parentDir = f.getParentFile();
if (parentDir == null) {
return; // do not monitor current directory implicitly
}

filesToWatch.put(file, modified);
File parentDir = f.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}

long modified = 0;
if (f.exists()) {
modified = f.lastModified();
}
filesToWatch.put(file, modified);
registerDir(Paths.get(parentDir.getAbsolutePath()));
}

Expand Down Expand Up @@ -248,7 +252,7 @@ protected synchronized void registerDir(Path path) {
}

protected WatchEvent.Kind<?>[] getEventKinds() {
List<WatchEvent.Kind<Path>> eventList = new LinkedList<>();
List<WatchEvent.Kind<Path>> eventList = new ArrayList<>();
if ((watchFlags & CREATE) == CREATE) {
eventList.add(StandardWatchEventKinds.ENTRY_CREATE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.Set;

import com.arm.cmsis.pack.common.CmsisConstants;
Expand Down Expand Up @@ -63,7 +63,7 @@ private Utils() {
*/
public static Collection<String> findFiles(File dir, String ext, Collection<String> files, int depth) {
if (files == null) {
files = new LinkedList<>();
files = new ArrayList<>();
}

File[] list = dir.listFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

package com.arm.cmsis.pack.build;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
Expand Down Expand Up @@ -149,7 +149,7 @@ protected Collection<String> createList(int type) {
case ASMINCPATHS_OPTION:
return new TreeSet<>(new AlnumComparator(false, true));
default:
return new LinkedList<>();
return new ArrayList<>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package com.arm.cmsis.pack.data;

import java.util.Collection;
import java.util.LinkedList;
import java.util.ArrayList;

import com.arm.cmsis.pack.common.CmsisConstants;
import com.arm.cmsis.pack.generic.IAttributes;
Expand Down Expand Up @@ -131,7 +131,7 @@ public Collection<ICpItem> getCompatibleDevices() {
}

protected Collection<ICpItem> getDevices(final String requiredTag) {
Collection<ICpItem> devices = new LinkedList<>();
Collection<ICpItem> devices = new ArrayList<>();
Collection<? extends ICpItem> children = getChildren();
if (children == null) {
return devices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
package com.arm.cmsis.pack.data;

import java.util.Collection;
import java.util.LinkedList;
import java.util.ArrayList;

import com.arm.cmsis.pack.common.CmsisConstants;
import com.arm.cmsis.pack.info.ICpComponentInfo;
Expand All @@ -24,7 +24,7 @@
*/
public class CpCodeTemplate extends CpItem implements ICpCodeTemplate {

Collection<String> fCodeTemplates = new LinkedList<>();
Collection<String> fCodeTemplates = new ArrayList<>();
ICpItemInfo fInfo;

/**
Expand Down
Loading

0 comments on commit 0dafd39

Please sign in to comment.