summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-11-22 21:06:40 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-11-22 21:12:20 +1000
commit76155fa4e9ef103de4b8283097f6cde18c6f1e08 (patch)
treede2e99a568bab8d9e15210d3945562f3c83feb25 /src
parent35f8908c214b5458ffe32c782dc81055773f5fb4 (diff)
downloadscala-76155fa4e9ef103de4b8283097f6cde18c6f1e08.tar.gz
scala-76155fa4e9ef103de4b8283097f6cde18c6f1e08.tar.bz2
scala-76155fa4e9ef103de4b8283097f6cde18c6f1e08.zip
Improve performance of REPL autocompletion
The code used to fuzzily match, e.g, `declasses` with `getDeclaredClasses` was exploring fruitless parts of the search space. The enclosed test case was hanging the REPL. This commit improves this by performing a prefix match of the unconsumed input against the current chunk of the candidate before exploring the `inits`. Fixes scala/scala-dev#271
Diffstat (limited to 'src')
-rw-r--r--src/interactive/scala/tools/nsc/interactive/Global.scala3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala
index 27a02c46a2..5c00d67888 100644
--- a/src/interactive/scala/tools/nsc/interactive/Global.scala
+++ b/src/interactive/scala/tools/nsc/interactive/Global.scala
@@ -1202,7 +1202,8 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
case Nil => entered.isEmpty && matchCount > 0
case head :: tail =>
val enteredAlternatives = Set(entered, entered.capitalize)
- head.inits.filter(_.length <= entered.length).exists(init =>
+ val n = (head, entered).zipped.count {case (c, e) => c == e || (c.isUpper && c == e.toUpper)}
+ head.take(n).inits.exists(init =>
enteredAlternatives.exists(entered =>
lenientMatch(entered.stripPrefix(init), tail, matchCount + (if (init.isEmpty) 0 else 1))
)