use static (And const where applicable) regular expression objects

the speed increase here is noticable since the work of creating a regex object is only done once per session
This commit is contained in:
garak
2022-11-22 22:57:26 -05:00
committed by t
parent d1bdbc2741
commit 37fcfba829
18 changed files with 79 additions and 56 deletions

View File

@@ -31,9 +31,11 @@ void Map::setName(QString mapName) {
QString Map::mapConstantFromName(QString mapName) {
// Transform map names of the form 'GraniteCave_B1F` into map constants like 'MAP_GRANITE_CAVE_B1F'.
QString nameWithUnderscores = mapName.replace(QRegularExpression("([a-z])([A-Z])"), "\\1_\\2");
static const QRegularExpression caseChange("([a-z])([A-Z])");
QString nameWithUnderscores = mapName.replace(caseChange, "\\1_\\2");
QString withMapAndUppercase = "MAP_" + nameWithUnderscores.toUpper();
QString constantName = withMapAndUppercase.replace(QRegularExpression("_+"), "_");
static const QRegularExpression underscores("_+");
QString constantName = withMapAndUppercase.replace(underscores, "_");
// Handle special cases.
// SSTidal needs to be SS_TIDAL, rather than SSTIDAL