Skip to content

Commit 971008e

Browse files
committed
performance optimization with very little to no noticeable effect
1 parent d97e3b0 commit 971008e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/main/java/vip/floatationdevice/wordlehelper/Common.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class Common
1717
public final static String answerWordsFile = "/common.txt";
1818
//file: all words file 'all.txt' in the jar
1919
public final static String allWordsFile = "/all.txt";
20-
//possible answer words
21-
public static ArrayList<String> answerWordsList = new ArrayList<String>();
22-
//all accepted words
23-
public static ArrayList<String> allWordsList = new ArrayList<String>();
20+
//possible answer words (from common.txt)
21+
public static ArrayList<String> answerWordsList = new ArrayList<String>(2500);
22+
//all accepted words (from all.txt)
23+
public static ArrayList<String> allWordsList = new ArrayList<String>(13000);
2424
//how many times you want the program to try to find the word. Can be overridden by command line argument
2525
public static int maxTries = 6;
2626
//wordle letter block background colors
@@ -65,34 +65,34 @@ public static void readAllWords() throws Exception
6565
public static void calculatePossibleWords(String inputWord, int[] result)
6666
{
6767
String inputWordLower = inputWord.toLowerCase();
68-
//remove this word if result isn't [1, 1, 1, 1, 1]
69-
//to prevent a possible bug
68+
//remove the word that have been identified as not being the answer
7069
if (!(result[0] == 1 && result[1] == 1 && result[2] == 1 && result[3] == 1 && result[4] == 1))
7170
answerWordsList.remove(inputWordLower);
71+
//calculation begins
7272
for (int loc = 0; loc != 5; loc++)
7373
{
7474
switch (result[loc])
7575
{
7676
case 2://the char is in another location
7777
{
7878
//keep the words that have the char
79-
ArrayList<String> temp = new ArrayList<String>();
79+
ArrayList<String> temp = new ArrayList<String>(2000);
8080
for (String word : answerWordsList) if (word.contains(inputWordLower.charAt(loc)+"")) temp.add(word);
8181
answerWordsList = temp;
8282
break;
8383
}
8484
case 1://the char is in the right location
8585
{
8686
//keep the words that have the same char at the same location
87-
ArrayList<String> temp = new ArrayList<String>();
87+
ArrayList<String> temp = new ArrayList<String>(2000);
8888
for (String word : answerWordsList) if (word.charAt(loc) == inputWordLower.charAt(loc)) temp.add(word);
8989
answerWordsList = temp;
9090
break;
9191
}
9292
case 0://the char is not in the answer word
9393
{
9494
//remove the words that have the same char that is not matched
95-
ArrayList<String> temp = new ArrayList<String>();
95+
ArrayList<String> temp = new ArrayList<String>(2000);
9696
for (String word : answerWordsList) if (!word.contains(inputWordLower.charAt(loc)+"")) temp.add(word);
9797
answerWordsList = temp;
9898
break;

src/main/java/vip/floatationdevice/wordlehelper/GUI.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ public void actionPerformed(ActionEvent e)
362362

363363
public static void main(String[] args)
364364
{
365+
long startTime=System.currentTimeMillis();
365366
new GUI().setVisible(true);
367+
System.out.println("Startup time: "+(System.currentTimeMillis()-startTime)+"ms");
366368
}
367369
}

0 commit comments

Comments
 (0)