Skip to content

Commit

Permalink
Replace deprecated stack with list
Browse files Browse the repository at this point in the history
shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala:35: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
    val rest = new mutable.Stack[immutable.BitSet]
                           ^
shared/src/main/scala/scala/xml/include/sax/XIncluder.scala:129: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
  private val entities = new mutable.Stack[String]()
                                     ^
shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala:42: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
  val attribStack = new mutable.Stack[MetaData]
                                ^
shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala:43: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
  val hStack = new mutable.Stack[Node] // [ element ] contains siblings
                           ^
shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala:44: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
  val tagStack = new mutable.Stack[String]
                             ^
shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala:45: class Stack in package mutable is deprecated (since 2.12.0): Stack is an inelegant and potentially poorly-performing wrapper around List. Use a List assigned to a var instead.
  var scopeStack = new mutable.Stack[NamespaceBinding]
                               ^
  • Loading branch information
ashawley committed Apr 18, 2019
1 parent e0e7df1 commit 39753a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -43,15 +43,16 @@ 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)
}
}

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
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/scala/xml/factory/XMLLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
7 changes: 3 additions & 4 deletions shared/src/main/scala/scala/xml/include/sax/XIncluder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand All @@ -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 = {}
Expand Down
40 changes: 23 additions & 17 deletions shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -148,16 +147,16 @@ 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
}

/**
* captures text, possibly normalizing whitespace
*/
def captureText(): Unit = {
if (capture && buffer.length > 0)
hStack push createText(buffer.toString)
hStack = createText(buffer.toString) :: hStack

buffer.clear()
}
Expand All @@ -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
}

Expand All @@ -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)
}
}

0 comments on commit 39753a6

Please sign in to comment.