Skip to content

Commit d985903

Browse files
committed
Cache classloaders in Splicer
1 parent 14187e2 commit d985903

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ object Splicer {
9393
}
9494
}
9595

96+
private val classLoaders = scala.collection.mutable.HashMap.empty[String, URLClassLoader]
97+
9698
/** Tree interpreter that can interpret calls to static methods with it's default arguments
9799
*
98100
* The interpreter assumes that all calls in the trees are to code that was
@@ -101,8 +103,12 @@ object Splicer {
101103
private class Interpreter(pos: Position)(implicit ctx: Context) {
102104

103105
private[this] val classLoader = {
104-
val urls = ctx.settings.classpath.value.split(':').map(cp => java.nio.file.Paths.get(cp).toUri.toURL)
105-
new URLClassLoader(urls, getClass.getClassLoader)
106+
val cp = ctx.settings.classpath.value
107+
def newClassLoader = {
108+
val urls = cp.split(':').map(cp => java.nio.file.Paths.get(cp).toUri.toURL)
109+
new URLClassLoader(urls, getClass.getClassLoader)
110+
}
111+
classLoaders.getOrElseUpdate(cp, newClassLoader)
106112
}
107113

108114
/** Returns the interpreted result of interpreting the code a call to the symbol with default arguments.

0 commit comments

Comments
 (0)