Faster 'false' results for isStats, as proposed by @SomeTroglodyte in #4259

This commit is contained in:
Yair Morgenstern 2021-06-25 18:33:45 +03:00
parent 7b7101b0b7
commit 823e6ffc2a

View File

@ -118,7 +118,10 @@ open class Stats() {
private val statRegexPattern = "([+-])(\\d+) ($allStatNames)"
private val statRegex = Regex(statRegexPattern)
private val entireStringRegexPattern = Regex("$statRegexPattern(, $statRegexPattern)*")
fun isStats(string:String): Boolean = entireStringRegexPattern.matches(string)
fun isStats(string:String): Boolean {
if (string[0] != '+' && string[0] != '-') return false // very quick negative check before the heavy Regex
return entireStringRegexPattern.matches(string)
}
fun parse(string:String):Stats{
val toReturn = Stats()
val statsWithBonuses = string.split(", ")