File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
shared/src/main/scala/scala/xml/factory Expand file tree Collapse file tree 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] {
2727 import scala .xml .Source ._
2828 def adapter : FactoryAdapter = new NoBindingFactoryAdapter ()
2929
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+ }
3537 }
3638
39+ /* Override this to use a different SAXParser. */
40+ def parser : SAXParser = parserInstance.get
41+
3742 /**
3843 * Loads XML from the given InputSource, using the supplied parser.
3944 * The methods available in scala.xml.XML use the XML parser in the JDK.
@@ -62,4 +67,4 @@ trait XMLLoader[T <: Node] {
6267
6368 /** Loads XML from the given String. */
6469 def loadString (string : String ): T = loadXML(fromString(string), parser)
65- }
70+ }
You can’t perform that action at this time.
0 commit comments