Skip to content

Commit 1715b8a

Browse files
authored
Merge pull request #163 from ashawley/revert-150
Reverting PR #150
2 parents bb611b3 + 1e8c888 commit 1715b8a

File tree

6 files changed

+39
-82
lines changed

6 files changed

+39
-82
lines changed

build.sbt

+2-15
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,8 @@ lazy val xml = crossProject.in(file("."))
3131
// http://stackoverflow.com/questions/16934488
3232
file(System.getProperty("sun.boot.class.path").split(java.io.File.pathSeparator).filter(_.endsWith(java.io.File.separator + "rt.jar")).head)
3333
-> url("http://docs.oracle.com/javase/8/docs/api")
34-
),
35-
36-
mimaBinaryIssueFilters ++= {
37-
import com.typesafe.tools.mima.core._
38-
import com.typesafe.tools.mima.core.ProblemFilters._
39-
Seq(
40-
// Scala 2.12 deprecated mutable.Stack, so we broke
41-
// binary compatibility for 1.1.0 in the following way:
42-
exclude[IncompatibleMethTypeProblem]("scala.xml.parsing.FactoryAdapter.scopeStack_="),
43-
exclude[IncompatibleResultTypeProblem]("scala.xml.parsing.FactoryAdapter.hStack"),
44-
exclude[IncompatibleResultTypeProblem]("scala.xml.parsing.FactoryAdapter.scopeStack"),
45-
exclude[IncompatibleResultTypeProblem]("scala.xml.parsing.FactoryAdapter.attribStack"),
46-
exclude[IncompatibleResultTypeProblem]("scala.xml.parsing.FactoryAdapter.tagStack")
47-
)
48-
})
34+
)
35+
)
4936
.jvmSettings(
5037
OsgiKeys.exportPackage := Seq(s"scala.xml.*;version=${version.value}"),
5138

jvm/src/test/scala/scala/xml/XMLTest.scala

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class XMLTestJVM {
4040
override def text = ""
4141
}
4242

43-
assertEquals(c, parsedxml11)
44-
assertEquals(parsedxml1, parsedxml11)
43+
assertTrue(c == parsedxml11)
44+
assertTrue(parsedxml1 == parsedxml11)
4545
assertTrue(List(parsedxml1) sameElements List(parsedxml11))
4646
assertTrue(Array(parsedxml1).toList sameElements List(parsedxml11))
4747

@@ -50,10 +50,10 @@ class XMLTestJVM {
5050
val i = new InputSource(new StringReader(x2))
5151
val x2p = scala.xml.XML.load(i)
5252

53-
assertEquals(Elem(null, "book", e, sc,
53+
assertTrue(x2p == Elem(null, "book", e, sc,
5454
Elem(null, "author", e, sc, Text("Peter Buneman")),
5555
Elem(null, "author", e, sc, Text("Dan Suciu")),
56-
Elem(null, "title", e, sc, Text("Data on ze web"))), x2p)
56+
Elem(null, "title", e, sc, Text("Data on ze web"))))
5757

5858
}
5959

@@ -454,16 +454,16 @@ class XMLTestJVM {
454454
@UnitTest
455455
def t6939 = {
456456
val foo = <x:foo xmlns:x="http://foo.com/"><x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo>
457-
assertEquals(foo.child.head.scope.toString, """ xmlns:x="http://bar.com/"""")
457+
assertTrue(foo.child.head.scope.toString == """ xmlns:x="http://bar.com/"""")
458458

459459
val fooDefault = <foo xmlns="http://foo.com/"><bar xmlns="http://bar.com/"><baz/></bar></foo>
460-
assertEquals(fooDefault.child.head.scope.toString, """ xmlns="http://bar.com/"""")
460+
assertTrue(fooDefault.child.head.scope.toString == """ xmlns="http://bar.com/"""")
461461

462462
val foo2 = scala.xml.XML.loadString("""<x:foo xmlns:x="http://foo.com/"><x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo>""")
463-
assertEquals(foo2.child.head.scope.toString, """ xmlns:x="http://bar.com/"""")
463+
assertTrue(foo2.child.head.scope.toString == """ xmlns:x="http://bar.com/"""")
464464

465465
val foo2Default = scala.xml.XML.loadString("""<foo xmlns="http://foo.com/"><bar xmlns="http://bar.com/"><baz/></bar></foo>""")
466-
assertEquals(foo2Default.child.head.scope.toString, """ xmlns="http://bar.com/"""")
466+
assertTrue(foo2Default.child.head.scope.toString == """ xmlns="http://bar.com/"""")
467467
}
468468

469469
@UnitTest

shared/src/main/scala/scala/xml/dtd/impl/SubsetConstruction.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
3232
val delta = new mutable.HashMap[immutable.BitSet, mutable.HashMap[T, immutable.BitSet]]
3333
var deftrans = mutable.Map(q0 -> sink, sink -> sink) // initial transitions
3434
var finals: mutable.Map[immutable.BitSet, Int] = mutable.Map()
35-
var rest = immutable.List.empty[immutable.BitSet]
35+
val rest = new mutable.Stack[immutable.BitSet]
3636

37-
rest = q0 :: sink :: rest
37+
rest.push(sink, q0)
3838

3939
def addFinal(q: immutable.BitSet) {
4040
if (nfa containsFinal q)
@@ -43,16 +43,15 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
4343
def add(Q: immutable.BitSet) {
4444
if (!states(Q)) {
4545
states += Q
46-
rest = Q :: rest
46+
rest push Q
4747
addFinal(Q)
4848
}
4949
}
5050

5151
addFinal(q0) // initial state may also be a final state
5252

5353
while (!rest.isEmpty) {
54-
val P = rest.head
55-
rest = rest.tail
54+
val P = rest.pop()
5655
// assign a number to this bitset
5756
indexMap = indexMap.updated(P, ix)
5857
invIndexMap = invIndexMap.updated(ix, P)

shared/src/main/scala/scala/xml/factory/XMLLoader.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ trait XMLLoader[T <: Node] {
3737
def loadXML(source: InputSource, parser: SAXParser): T = {
3838
val newAdapter = adapter
3939

40-
newAdapter.scopeStack = TopScope :: newAdapter.scopeStack
40+
newAdapter.scopeStack push TopScope
4141
parser.parse(source, newAdapter)
42-
newAdapter.scopeStack = newAdapter.scopeStack.tail
42+
newAdapter.scopeStack.pop()
4343

4444
newAdapter.rootElem.asInstanceOf[T]
4545
}

shared/src/main/scala/scala/xml/include/sax/XIncluder.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package scala
1010
package xml
1111
package include.sax
1212

13+
import scala.collection.mutable
1314
import org.xml.sax.{ ContentHandler, Locator, Attributes }
1415
import org.xml.sax.ext.LexicalHandler
1516
import java.io.{ OutputStream, OutputStreamWriter, IOException }
@@ -125,7 +126,7 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
125126

126127
// LexicalHandler methods
127128
private var inDTD: Boolean = false
128-
private var entities = List.empty[String]
129+
private val entities = new mutable.Stack[String]()
129130

130131
def startDTD(name: String, publicID: String, systemID: String) {
131132
inDTD = true
@@ -144,12 +145,12 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
144145
}
145146
def endDTD() {}
146147

147-
def startEntity(name: String): Unit = {
148-
entities = name :: entities
148+
def startEntity(name: String) {
149+
entities push name
149150
}
150151

151-
def endEntity(name: String): Unit = {
152-
entities = entities.tail
152+
def endEntity(name: String) {
153+
entities.pop()
153154
}
154155

155156
def startCDATA() {}

shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala

+17-47
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package scala
1010
package xml
1111
package parsing
1212

13+
import scala.collection.{ mutable, Iterator }
1314
import org.xml.sax.Attributes
1415
import org.xml.sax.helpers.DefaultHandler
1516

@@ -38,34 +39,10 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
3839
var rootElem: Node = null
3940

4041
val buffer = new StringBuilder()
41-
/** List of attributes
42-
*
43-
* Previously was a mutable [[scala.collection.mutable.Stack Stack]], but is now a mutable reference to an immutable [[scala.collection.immutable.List List]].
44-
*
45-
* @since 1.1.0
46-
*/
47-
var attribStack = List.empty[MetaData]
48-
/** List of elements
49-
*
50-
* Previously was a mutable [[scala.collection.mutable.Stack Stack]], but is now a mutable reference to an immutable [[scala.collection.immutable.List List]].
51-
*
52-
* @since 1.1.0
53-
*/
54-
var hStack = List.empty[Node] // [ element ] contains siblings
55-
/** List of element names
56-
*
57-
* Previously was a mutable [[scala.collection.mutable.Stack Stack]], but is now a mutable reference to an immutable [[scala.collection.immutable.List List]].
58-
*
59-
* @since 1.1.0
60-
*/
61-
var tagStack = List.empty[String]
62-
/** List of namespaces
63-
*
64-
* Previously was a mutable [[scala.collection.mutable.Stack Stack]], but is now a mutable reference to an immutable [[scala.collection.immutable.List List]].
65-
*
66-
* @since 1.1.0
67-
*/
68-
var scopeStack = List.empty[NamespaceBinding]
42+
val attribStack = new mutable.Stack[MetaData]
43+
val hStack = new mutable.Stack[Node] // [ element ] contains siblings
44+
val tagStack = new mutable.Stack[String]
45+
var scopeStack = new mutable.Stack[NamespaceBinding]
6946

7047
var curTag: String = null
7148
var capture: Boolean = false
@@ -145,17 +122,17 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
145122
attributes: Attributes): Unit =
146123
{
147124
captureText()
148-
tagStack = curTag :: tagStack
125+
tagStack push curTag
149126
curTag = qname
150127

151128
val localName = splitName(qname)._2
152129
capture = nodeContainsText(localName)
153130

154-
hStack = null :: hStack
131+
hStack push null
155132
var m: MetaData = Null
156133
var scpe: NamespaceBinding =
157134
if (scopeStack.isEmpty) TopScope
158-
else scopeStack.head
135+
else scopeStack.top
159136

160137
for (i <- 0 until attributes.getLength()) {
161138
val qname = attributes getQName i
@@ -170,16 +147,16 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
170147
m = Attribute(Option(pre), key, Text(value), m)
171148
}
172149

173-
scopeStack = scpe :: scopeStack
174-
attribStack = m :: attribStack
150+
scopeStack push scpe
151+
attribStack push m
175152
}
176153

177154
/**
178155
* captures text, possibly normalizing whitespace
179156
*/
180157
def captureText(): Unit = {
181158
if (capture && buffer.length > 0)
182-
hStack = createText(buffer.toString) :: hStack
159+
hStack push createText(buffer.toString)
183160

184161
buffer.clear()
185162
}
@@ -193,24 +170,17 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
193170
*/
194171
override def endElement(uri: String, _localName: String, qname: String): Unit = {
195172
captureText()
196-
val metaData = attribStack.head
197-
attribStack = attribStack.tail
173+
val metaData = attribStack.pop()
198174

199175
// reverse order to get it right
200-
val v = hStack.takeWhile(_ != null).reverse
201-
hStack = hStack.dropWhile(_ != null) match {
202-
case null :: hs => hs
203-
case hs => hs
204-
}
176+
val v = (Iterator continually hStack.pop takeWhile (_ != null)).toList.reverse
205177
val (pre, localName) = splitName(qname)
206-
val scp = scopeStack.head
207-
scopeStack = scopeStack.tail
178+
val scp = scopeStack.pop()
208179

209180
// create element
210181
rootElem = createNode(pre, localName, metaData, scp, v)
211-
hStack = rootElem :: hStack
212-
curTag = tagStack.head
213-
tagStack = tagStack.tail
182+
hStack push rootElem
183+
curTag = tagStack.pop()
214184
capture = curTag != null && nodeContainsText(curTag) // root level
215185
}
216186

@@ -219,6 +189,6 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
219189
*/
220190
override def processingInstruction(target: String, data: String) {
221191
captureText()
222-
hStack = hStack.reverse_:::(createProcInstr(target, data).toList)
192+
hStack pushAll createProcInstr(target, data)
223193
}
224194
}

0 commit comments

Comments
 (0)