From da1bdba0f8000cdb99c7a2016b12b6fb9d370ce9 Mon Sep 17 00:00:00 2001 From: Paul Draper Date: Sun, 10 Apr 2016 17:03:19 -0600 Subject: [PATCH] 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. --- .../src/main/scala/sbt/complete/Parsers.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/util/complete/src/main/scala/sbt/complete/Parsers.scala b/util/complete/src/main/scala/sbt/complete/Parsers.scala index 3183929e8..8a666cfc1 100644 --- a/util/complete/src/main/scala/sbt/complete/Parsers.scala +++ b/util/complete/src/main/scala/sbt/complete/Parsers.scala @@ -264,5 +264,19 @@ object DefaultParsers extends Parsers with ParserMain { apply(p)(s).resultEmpty.isValid /** 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 + } } \ No newline at end of file