Skip to content

Commit

Permalink
Merge pull request #176 from shado23/threadlocal-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
SethTisue authored Mar 4, 2021
2 parents d360cb6 + 0aab600 commit 43dc3ef
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions shared/src/main/scala/scala/xml/factory/XMLLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ trait XMLLoader[T <: Node] {
import scala.xml.Source._
def adapter: FactoryAdapter = new NoBindingFactoryAdapter()

/* Override this to use a different SAXParser. */
def parser: SAXParser = {
val f = SAXParserFactory.newInstance()
f.setNamespaceAware(false)
f.newSAXParser()
private lazy val parserInstance = new ThreadLocal[SAXParser] {
override def initialValue = {
val parser = SAXParserFactory.newInstance()

parser.setNamespaceAware(false)
parser.newSAXParser()
}
}

/* Override this to use a different SAXParser. */
def parser: SAXParser = parserInstance.get

/**
* Loads XML from the given InputSource, using the supplied parser.
* The methods available in scala.xml.XML use the XML parser in the JDK.
Expand Down Expand Up @@ -62,4 +67,4 @@ trait XMLLoader[T <: Node] {

/** Loads XML from the given String. */
def loadString(string: String): T = loadXML(fromString(string), parser)
}
}

0 comments on commit 43dc3ef

Please sign in to comment.