Optimize FileSection.parse()/parseMap().

This was showing up in profiles with simulation AI. The change
makes constants for the patterns used, so they don't have to be
"compiled" each time and also introduces a cache for these.

With this change, a GameCopier operation is sped up by about 30%
from my local measurement (I tried with a modern deck I have).
This commit is contained in:
Alexei Svitkine
2019-12-20 11:22:06 -05:00
parent 0e1c82a31f
commit dd4df9baaa
15 changed files with 69 additions and 53 deletions

View File

@@ -96,7 +96,7 @@ public class CustomLimited extends DeckBase {
* @return the custom limited
*/
public static CustomLimited parse(final List<String> dfData, final IStorage<Deck> cubes) {
final FileSection data = FileSection.parse(dfData, ":");
final FileSection data = FileSection.parse(dfData, FileSection.COLON_KV_SEPARATOR);
List<Pair<String, Integer>> slots = new ArrayList<>();
String boosterData = data.get("Booster");

View File

@@ -133,7 +133,7 @@ public class ForgeProfileProperties {
private static Map<String, String> getMap(final Properties props, final String propertyKey) {
final String strMap = props.getProperty(propertyKey, "").trim();
return FileSection.parseToMap(strMap, "->", "|");
return FileSection.parseToMap(strMap, FileSection.ARROW_KV_SEPARATOR);
}
private static int getInt(final Properties props, final String propertyKey, final int defaultValue) {

View File

@@ -43,7 +43,7 @@ public class SellRules {
return;
}
FileSection section = FileSection.parse(questShop, "=");
FileSection section = FileSection.parse(questShop, FileSection.EQUALS_KV_SEPARATOR);
minWins = section.getInt("WinsToUnlock");
cost = section.getInt("Credits", 250);
maxDifficulty = section.getInt("MaxDifficulty", 5);

View File

@@ -28,7 +28,7 @@ public class QuestChallengeReader extends StorageReaderFolder<QuestEventChalleng
final QuestEventChallenge qc = new QuestEventChallenge();
// Unique properties
FileSection sectionQuest = FileSection.parse(contents.get("quest"), "=");
FileSection sectionQuest = FileSection.parse(contents.get("quest"), FileSection.EQUALS_KV_SEPARATOR);
qc.setId(sectionQuest.get("ID", "-1"));
qc.setOpponentName(sectionQuest.get("OpponentName"));
qc.setRepeatable(sectionQuest.getBoolean("Repeat", false));
@@ -60,7 +60,7 @@ public class QuestChallengeReader extends StorageReaderFolder<QuestEventChalleng
}
// Common properties
FileSection sectionMeta = FileSection.parse(contents.get("metadata"), "=");
FileSection sectionMeta = FileSection.parse(contents.get("metadata"), FileSection.EQUALS_KV_SEPARATOR);
qc.setTitle(sectionMeta.get("Title"));
qc.setName(qc.getTitle()); // Challenges have unique titles
qc.setDifficulty(QuestEventDifficulty.fromString(sectionMeta.get("Difficulty")));

View File

@@ -27,7 +27,7 @@ public class QuestDuelReader extends StorageReaderFolder<QuestEventDuel> {
final QuestEventDuel qc = new QuestEventDuel();
// Common properties
FileSection sectionMeta = FileSection.parse(contents.get("metadata"), "=");
FileSection sectionMeta = FileSection.parse(contents.get("metadata"), FileSection.EQUALS_KV_SEPARATOR);
qc.setTitle(sectionMeta.get("Title"));
qc.setName(sectionMeta.get("Name")); // Challenges have unique titles
qc.setDifficulty(QuestEventDifficulty.fromString(sectionMeta.get("Difficulty")));