diff --git a/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala b/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala index 2bc2c97b1..e3d2ba194 100644 --- a/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala +++ b/shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala @@ -32,9 +32,9 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T]) val delta = new mutable.HashMap[immutable.BitSet, mutable.HashMap[T, immutable.BitSet]] val deftrans = mutable.Map(q0 -> sink, sink -> sink) // initial transitions val finals: mutable.Map[immutable.BitSet, Int] = mutable.Map() - val rest = new mutable.Stack[immutable.BitSet] + var rest = immutable.List.empty[immutable.BitSet] - rest.push(sink, q0) + rest = q0 :: sink :: rest def addFinal(q: immutable.BitSet): Unit = { if (nfa containsFinal q) @@ -43,7 +43,7 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T]) def add(Q: immutable.BitSet): Unit = { if (!states(Q)) { states += Q - rest push Q + rest = Q :: rest addFinal(Q) } } @@ -51,7 +51,8 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T]) addFinal(q0) // initial state may also be a final state while (!rest.isEmpty) { - val P = rest.pop() + val P = rest.head + rest = rest.tail // assign a number to this bitset indexMap(P) = ix invIndexMap(ix) = P diff --git a/shared/src/main/scala/scala/xml/factory/XMLLoader.scala b/shared/src/main/scala/scala/xml/factory/XMLLoader.scala index b84f42af4..e9a534fbd 100644 --- a/shared/src/main/scala/scala/xml/factory/XMLLoader.scala +++ b/shared/src/main/scala/scala/xml/factory/XMLLoader.scala @@ -37,9 +37,9 @@ trait XMLLoader[T <: Node] { def loadXML(source: InputSource, parser: SAXParser): T = { val newAdapter = adapter - newAdapter.scopeStack push TopScope + newAdapter.scopeStack = TopScope :: newAdapter.scopeStack parser.parse(source, newAdapter) - newAdapter.scopeStack.pop() + newAdapter.scopeStack = newAdapter.scopeStack.tail newAdapter.rootElem.asInstanceOf[T] } diff --git a/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala b/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala index 2f6284a6c..bf65cfafc 100644 --- a/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala +++ b/shared/src/main/scala/scala/xml/include/sax/XIncluder.scala @@ -10,7 +10,6 @@ package scala package xml package include.sax -import scala.collection.mutable import org.xml.sax.{ ContentHandler, Locator, Attributes } import org.xml.sax.ext.LexicalHandler import java.io.{ OutputStream, OutputStreamWriter, IOException } @@ -126,7 +125,7 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit // LexicalHandler methods private var inDTD: Boolean = false - private val entities = new mutable.Stack[String]() + private var entities = List.empty[String] def startDTD(name: String, publicID: String, systemID: String): Unit = { inDTD = true @@ -146,11 +145,11 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit def endDTD(): Unit = {} def startEntity(name: String): Unit = { - entities push name + entities = name :: entities } def endEntity(name: String): Unit = { - entities.pop() + entities = entities.tail } def startCDATA(): Unit = {} diff --git a/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala b/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala index cbacb0492..5751bf670 100644 --- a/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala +++ b/shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala @@ -10,7 +10,6 @@ package scala package xml package parsing -import scala.collection.{ mutable, Iterator } import scala.collection.Seq import org.xml.sax.Attributes import org.xml.sax.helpers.DefaultHandler @@ -40,10 +39,10 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node var rootElem: Node = null val buffer = new StringBuilder() - val attribStack = new mutable.Stack[MetaData] - val hStack = new mutable.Stack[Node] // [ element ] contains siblings - val tagStack = new mutable.Stack[String] - var scopeStack = new mutable.Stack[NamespaceBinding] + var attribStack = List.empty[MetaData] + var hStack = List.empty[Node] // [ element ] contains siblings + var tagStack = List.empty[String] + var scopeStack = List.empty[NamespaceBinding] var curTag: String = null var capture: Boolean = false @@ -123,17 +122,17 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node attributes: Attributes): Unit = { captureText() - tagStack push curTag + tagStack = curTag :: tagStack curTag = qname val localName = splitName(qname)._2 capture = nodeContainsText(localName) - hStack push null + hStack = null :: hStack var m: MetaData = Null var scpe: NamespaceBinding = if (scopeStack.isEmpty) TopScope - else scopeStack.top + else scopeStack.head for (i <- 0 until attributes.getLength()) { val qname = attributes getQName i @@ -148,8 +147,8 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node m = Attribute(Option(pre), key, Text(value), m) } - scopeStack push scpe - attribStack push m + scopeStack = scpe :: scopeStack + attribStack = m :: attribStack } /** @@ -157,7 +156,7 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node */ def captureText(): Unit = { if (capture && buffer.length > 0) - hStack push createText(buffer.toString) + hStack = createText(buffer.toString) :: hStack buffer.clear() } @@ -171,17 +170,24 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node */ override def endElement(uri: String, _localName: String, qname: String): Unit = { captureText() - val metaData = attribStack.pop() + val metaData = attribStack.head + attribStack = attribStack.tail // reverse order to get it right - val v = (Iterator continually hStack.pop takeWhile (_ != null)).toList.reverse + val v = hStack.takeWhile(_ != null).reverse + hStack = hStack.dropWhile(_ != null) match { + case null :: hs => hs + case hs => hs + } val (pre, localName) = splitName(qname) - val scp = scopeStack.pop() + val scp = scopeStack.head + scopeStack = scopeStack.tail // create element rootElem = createNode(pre, localName, metaData, scp, v) - hStack push rootElem - curTag = tagStack.pop() + hStack = rootElem :: hStack + curTag = tagStack.head + tagStack = tagStack.tail capture = curTag != null && nodeContainsText(curTag) // root level } @@ -190,6 +196,6 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node */ override def processingInstruction(target: String, data: String): Unit = { captureText() - hStack pushAll createProcInstr(target, data) + hStack = hStack.reverse_:::(createProcInstr(target, data).toList) } }