Prevent allocation in loops
All checks were successful
build-and-test / test (push) Successful in 1m52s
build-and-test / generate-javadoc (push) Successful in 2m5s
build-and-test / build (push) Successful in 2m7s

This commit is contained in:
JeremyStar™ 2024-08-20 20:25:46 +02:00
parent ad7b3568cf
commit ca3bf94a48
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
6 changed files with 29 additions and 17 deletions

View file

@ -325,15 +325,17 @@ public final class Engine extends SubsystemClass {
Set<@NotNull Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(EngineSubsystem.class);
// Initialize classes, get dependency vector and add to 'subsystemsMutable'
Object initializedClassRaw;
SubsystemClass initializedClass;
for (Class<?> clazz : annotatedClasses) {
try {
// Create new instance
Object initializedClassRaw = clazz.getDeclaredConstructor().newInstance();
SubsystemClass initializedClass = null;
initializedClassRaw = clazz.getDeclaredConstructor().newInstance();
initializedClass = null;
// Check if class implements SubsystemMainClass
if (initializedClassRaw instanceof SubsystemClass subsystemInstance)
initializedClass = subsystemInstance;
if (initializedClassRaw instanceof SubsystemClass)
initializedClass = (SubsystemClass) initializedClassRaw;
else
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Does not implement " + SubsystemClass.class.getName());

View file

@ -131,7 +131,7 @@ public final class StarOpenSourceVersioningSystem implements VersioningSystem {
String companion = null;
String fork = null;
// Iterate through all chraracters
// Iterate through all characters
for (Character character : versionString.toCharArray()) {
switch (parsingId) {
case 0 -> { // 'v' character

View file

@ -44,7 +44,8 @@ public final class JvmArguments implements Placeholder {
StringBuilder arguments = new StringBuilder();
for (String argument : JvmInformation.getArguments()) {
if (!arguments.isEmpty()) arguments.append(" ");
if (!arguments.isEmpty())
arguments.append(" ");
arguments
.append("\"")

View file

@ -158,17 +158,23 @@ public final class DependencyResolver {
// provides
for (String dependency : vector.getDependencies()) {
// 0 = identifier
// 1 = version equal
// 2 = version smaller
// 3 = version bigger
int mode = 0;
boolean[] duplicateCheck = new boolean[3];
StringBuilder identifier = new StringBuilder();
StringBuilder versionEqual = new StringBuilder();
StringBuilder versionSmaller = new StringBuilder();
StringBuilder versionBigger = new StringBuilder();
int mode;
boolean[] duplicateCheck;
StringBuilder identifier;
StringBuilder versionEqual;
StringBuilder versionSmaller;
StringBuilder versionBigger;
for (String dependency : vector.getDependencies()) {
mode = 0;
duplicateCheck = new boolean[3];
identifier = new StringBuilder();
versionEqual = new StringBuilder();
versionSmaller = new StringBuilder();
versionBigger = new StringBuilder();
// Get variables
for (char character : dependency.toCharArray()) {

View file

@ -126,6 +126,7 @@ public final class Miscellaneous {
for (String separator : separators)
if (countOccurrences(string, separator) == requiredOccurrences)
return separator;
return null;
}
@ -142,6 +143,7 @@ public final class Miscellaneous {
for (String separator : separators)
if (countOccurrences(string, separator) >= minimumOccurrences)
return separator;
return null;
}

View file

@ -69,8 +69,9 @@ public class UnitLogger {
levelName = "TEST";
StringBuilder args = new StringBuilder();
boolean stringQuotes;
for (Object arg : additionalStuff) {
boolean stringQuotes = arg instanceof String;
stringQuotes = arg instanceof String;
// Print full class path for enums
if (arg instanceof Enum<?>) {