mirror of
https://github.com/sbt/sbt.git
synced 2026-08-22 06:07:24 +02:00
Improve performance for DefaultParsers.validID(String)
KeyIndex can call this method hundreds of thousands of times, so this change makes a significant difference in loading time.
This commit is contained in:
committed by
Dale Wijnand
parent
a58b184195
commit
da1bdba0f8
@@ -264,5 +264,19 @@ object DefaultParsers extends Parsers with ParserMain {
|
|||||||
apply(p)(s).resultEmpty.isValid
|
apply(p)(s).resultEmpty.isValid
|
||||||
|
|
||||||
/** Returns `true` if `s` parses successfully according to [[ID]].*/
|
/** Returns `true` if `s` parses successfully according to [[ID]].*/
|
||||||
def validID(s: String): Boolean = matches(ID, s)
|
def validID(s: String): Boolean = {
|
||||||
|
// matches(ID, s) would be simple but KeyIndex can call this method 100k's of times
|
||||||
|
val length = s.length
|
||||||
|
if (length == 0 || !s(0).isLetter) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var i = 1
|
||||||
|
while (i < length) {
|
||||||
|
if (!isIDChar(s(i))) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user