File tree 1 file changed +11
-6
lines changed
shared/src/main/scala/scala/xml/factory
1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -27,13 +27,18 @@ trait XMLLoader[T <: Node] {
27
27
import scala .xml .Source ._
28
28
def adapter : FactoryAdapter = new NoBindingFactoryAdapter ()
29
29
30
- /* Override this to use a different SAXParser. */
31
- def parser : SAXParser = {
32
- val f = SAXParserFactory .newInstance()
33
- f.setNamespaceAware(false )
34
- f.newSAXParser()
30
+ private lazy val parserInstance = new ThreadLocal [SAXParser ] {
31
+ override def initialValue = {
32
+ val parser = SAXParserFactory .newInstance()
33
+
34
+ parser.setNamespaceAware(false )
35
+ parser.newSAXParser()
36
+ }
35
37
}
36
38
39
+ /* Override this to use a different SAXParser. */
40
+ def parser : SAXParser = parserInstance.get
41
+
37
42
/**
38
43
* Loads XML from the given InputSource, using the supplied parser.
39
44
* The methods available in scala.xml.XML use the XML parser in the JDK.
@@ -62,4 +67,4 @@ trait XMLLoader[T <: Node] {
62
67
63
68
/** Loads XML from the given String. */
64
69
def loadString (string : String ): T = loadXML(fromString(string), parser)
65
- }
70
+ }
You can’t perform that action at this time.
0 commit comments