mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-01 02:14:51 +07:00
Faster 'false' results for isStats, as proposed by @SomeTroglodyte in #4259
This commit is contained in:
parent
7b7101b0b7
commit
823e6ffc2a
@ -118,7 +118,10 @@ open class Stats() {
|
|||||||
private val statRegexPattern = "([+-])(\\d+) ($allStatNames)"
|
private val statRegexPattern = "([+-])(\\d+) ($allStatNames)"
|
||||||
private val statRegex = Regex(statRegexPattern)
|
private val statRegex = Regex(statRegexPattern)
|
||||||
private val entireStringRegexPattern = Regex("$statRegexPattern(, $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{
|
fun parse(string:String):Stats{
|
||||||
val toReturn = Stats()
|
val toReturn = Stats()
|
||||||
val statsWithBonuses = string.split(", ")
|
val statsWithBonuses = string.split(", ")
|
||||||
|
Loading…
Reference in New Issue
Block a user