@@ -10,6 +10,8 @@ package scala
10
10
package util .parsing .input
11
11
12
12
import scala .collection .mutable .ArrayBuffer
13
+ import java .lang .{CharSequence , ThreadLocal }
14
+ import java .util .WeakHashMap
13
15
14
16
/** `OffsetPosition` is a standard class for positions
15
17
* represented as offsets into a source ``document''.
@@ -19,7 +21,7 @@ import scala.collection.mutable.ArrayBuffer
19
21
*
20
22
* @author Martin Odersky
21
23
*/
22
- case class OffsetPosition (source : java.lang. CharSequence , offset : Int ) extends Position {
24
+ case class OffsetPosition (source : CharSequence , offset : Int ) extends Position {
23
25
24
26
/** An index that contains all line starts, including first line, and eof. */
25
27
private lazy val index : Array [Int ] = {
@@ -87,6 +89,11 @@ case class OffsetPosition(source: java.lang.CharSequence, offset: Int) extends P
87
89
* @author Tomáš Janoušek
88
90
*/
89
91
object OffsetPosition {
90
- private lazy val indexCache = java.util.Collections .synchronizedMap(
91
- new java.util.WeakHashMap [java.lang.CharSequence , Array [Int ]])
92
+ private lazy val indexCacheTL =
93
+ // not DynamicVariable as that would share the map from parent to child :-(
94
+ new ThreadLocal [java.util.Map [CharSequence , Array [Int ]]] {
95
+ override def initialValue = new WeakHashMap [CharSequence , Array [Int ]]
96
+ }
97
+
98
+ private def indexCache = indexCacheTL.get
92
99
}
0 commit comments