Skip to content

Commit

Permalink
Merge pull request #210 from ashawley/2.13-collections
Browse files Browse the repository at this point in the history
Re-work 2.13 collections changes
  • Loading branch information
ashawley authored Apr 18, 2018
2 parents 1b951af + 4d1d67a commit e02c2be
Show file tree
Hide file tree
Showing 46 changed files with 79 additions and 17 deletions.
1 change: 1 addition & 0 deletions jvm/src/test/scala/scala/xml/ReuseNodesTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.xml

import scala.xml.transform._
import scala.collection.Seq
import org.junit.Assert.assertSame
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
Expand Down
1 change: 1 addition & 0 deletions jvm/src/test/scala/scala/xml/SerializationTest.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scala.xml

import scala.collection.Seq
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down
1 change: 1 addition & 0 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import java.io.StringWriter
import java.io.ByteArrayOutputStream
import java.io.StringReader
import scala.collection.Iterable
import scala.collection.Seq
import scala.xml.Utility.sort

object XMLTestJVM {
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/Atom.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* The class `Atom` provides an XML node for text (`PCDATA`).
* It is used in both non-bound and bound XML representations.
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/Attribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* This singleton object contains the `apply` and `unapply` methods for
* convenient construction and deconstruction.
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/Document.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* A document information item (according to InfoSet spec). The comments
* are copied from the Infoset spec, only augmented with some information
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/Elem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package scala
package xml

import scala.collection.Seq

/**
* This singleton object contains the `apply` and `unapplySeq` methods for
* convenient construction and deconstruction. It is possible to deconstruct
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/Equality.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* In an attempt to contain the damage being inflicted on consistency by the
* ad hoc `equals` methods spread around `xml`, the logic is centralized and
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/Group.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* A hack to group XML nodes in one node for output.
*
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/MetaData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package xml
import Utility.sbToString
import scala.annotation.tailrec
import scala.collection.AbstractIterable
import scala.collection.Seq

object MetaData {
/**
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/NamespaceBinding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package scala
package xml

import scala.collection.Seq
import Utility.sbToString

/**
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* This singleton object contains the `unapplySeq` method for
* convenient deconstruction.
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/NodeSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import scala.collection.{ mutable, immutable, generic, SeqLike, AbstractSeq }
import mutable.{ Builder, ListBuffer }
import generic.{ CanBuildFrom }
import scala.language.implicitConversions
import scala.collection.Seq

/**
* This object ...
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/Null.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package xml

import Utility.isNameStart
import scala.collection.Iterator
import scala.collection.Seq

/**
* Essentially, every method in here is a dummy, returning Zero[T].
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/PrefixedAttribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* prefixed attributes always have a non-null namespace.
*
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package scala
package xml

import scala.collection.Seq
import Utility.sbToString

/**
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/TextBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package scala
package xml

import scala.collection.Seq
import Utility.isSpace

object TextBuffer {
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/UnprefixedAttribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml

import scala.collection.Seq

/**
* Unprefixed attributes have the null namespace, and no prefix field
*
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package xml

import scala.collection.mutable
import scala.language.implicitConversions
import scala.collection.Seq

/**
* The `Utility` object provides utility functions for processing instances
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/Xhtml.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package xml

import parsing.XhtmlEntities
import Utility.{ sbToString, isAtomAndNotText }
import scala.collection.Seq

/* (c) David Pollak 2007 WorldWide Conferencing, LLC */

Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/dtd/ContentModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package scala
package xml
package dtd

import scala.collection.Seq
import scala.xml.dtd.impl._
import scala.xml.Utility.sbToString
import PartialFunction._
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/dtd/DTD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package xml
package dtd

import scala.collection.mutable
import scala.collection.Seq

/**
* A document type declaration.
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/dtd/DocType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package scala
package xml
package dtd

import scala.collection.Seq

/**
* An XML node for document type declaration.
*
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/scala/xml/dtd/ElementValidator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package dtd

import PartialFunction._
import scala.collection.mutable
import scala.collection.Seq

import ContentModel.ElemName
import MakeValidationException._ // @todo other exceptions
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/dtd/Scanner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package scala
package xml
package dtd

import scala.collection.Seq

/**
* Scanner for regexps (content models in DTD element declarations)
* todo: cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package scala
package xml.dtd.impl

import scala.collection.{ mutable, immutable }
import scala.collection.Seq

// todo: replace global variable pos with acc

Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/dtd/impl/Inclusion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package scala
package xml.dtd.impl

import scala.collection.Seq

/**
* A fast test of language inclusion between minimal automata.
* inspired by the ''AMoRE automata library''.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package scala
package xml.dtd.impl

import scala.collection.{ immutable, mutable }
import scala.collection.Seq

/**
* A nondeterministic automaton. States are integers, where
Expand Down Expand Up @@ -47,7 +48,7 @@ private[dtd] abstract class NondetWordAutom[T <: AnyRef] {
def nextDefault(Q: immutable.BitSet): immutable.BitSet = next(Q, default)

private def next(Q: immutable.BitSet, f: (Int) => immutable.BitSet): immutable.BitSet =
(Q map f).foldLeft(immutable.BitSet.empty)(_ ++ _)
Q.toSet.map(f).foldLeft(immutable.BitSet.empty)(_ ++ _)

private def finalStates = 0 until nstates filter isFinal
override def toString = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])

def determinize: DetWordAutom[T] = {
// for assigning numbers to bitsets
var indexMap = scala.collection.Map[immutable.BitSet, Int]()
var invIndexMap = scala.collection.Map[Int, immutable.BitSet]()
val indexMap = mutable.Map[immutable.BitSet, Int]()
val invIndexMap = mutable.Map[Int, immutable.BitSet]()
var ix = 0

// we compute the dfa with states = bitsets
Expand All @@ -30,15 +30,15 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])

var states = Set(q0, sink) // initial set of sets
val delta = new mutable.HashMap[immutable.BitSet, mutable.HashMap[T, immutable.BitSet]]
var deftrans = mutable.Map(q0 -> sink, sink -> sink) // initial transitions
var finals: mutable.Map[immutable.BitSet, Int] = mutable.Map()
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]

rest.push(sink, q0)

def addFinal(q: immutable.BitSet): Unit = {
if (nfa containsFinal q)
finals = finals.updated(q, selectTag(q, nfa.finals))
finals(q) = selectTag(q, nfa.finals)
}
def add(Q: immutable.BitSet): Unit = {
if (!states(Q)) {
Expand All @@ -53,8 +53,8 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
while (!rest.isEmpty) {
val P = rest.pop()
// assign a number to this bitset
indexMap = indexMap.updated(P, ix)
invIndexMap = invIndexMap.updated(ix, P)
indexMap(P) = ix
invIndexMap(ix) = P
ix += 1

// make transition map
Expand All @@ -69,7 +69,7 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])

// collect default transitions
val Pdef = nfa nextDefault P
deftrans = deftrans.updated(P, Pdef)
deftrans(P) = Pdef
add(Pdef)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package scala
package xml.dtd.impl

import scala.collection.{ immutable, mutable }
import scala.collection.Seq

/**
* This class turns a regular expression into a [[scala.util.automata.NondetWordAutom]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package scala
package xml
package factory

import scala.collection.Seq

/**
* This class logs what the nodefactory is actually doing.
* If you want to see what happens during loading, use it like this:
Expand Down
2 changes: 2 additions & 0 deletions shared/src/main/scala/scala/xml/factory/NodeFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package scala
package xml
package factory

import scala.collection.Seq

trait NodeFactory[A <: Node] {
val ignoreComments = false
val ignoreProcInstr = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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
16 changes: 8 additions & 8 deletions shared/src/main/scala/scala/xml/parsing/MarkupParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
nextch()
val str = cbuf.toString()
cbuf.length = 0
cbuf.setLength(0)
str
}

Expand Down Expand Up @@ -390,7 +390,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
xToken("--")
while (!eof) {
if (ch == '-' && { sb.append(ch); nextch(); ch == '-' }) {
sb.length = sb.length - 1
sb.setLength(sb.length - 1)
nextch()
xToken('>')
return handle.comment(pos, sb.toString())
Expand Down Expand Up @@ -608,7 +608,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
exit = eof || (ch == '<') || (ch == '&')
}
val str = cbuf.toString
cbuf.length = 0
cbuf.setLength(0)
str
}

Expand All @@ -630,7 +630,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
nextch()
val str = cbuf.toString()
cbuf.length = 0
cbuf.setLength(0)
str
}

Expand All @@ -653,7 +653,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
}
nextch()
val str = cbuf.toString
cbuf.length = 0
cbuf.setLength(0)
str
}

Expand Down Expand Up @@ -799,7 +799,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
//Console.println("END["+ch+"]")
nextch()
val cmstr = cbuf.toString()
cbuf.length = 0
cbuf.setLength(0)
handle.elemDecl(n, cmstr)
}

Expand All @@ -826,7 +826,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
nextch()
}
val atpe = cbuf.toString
cbuf.length = 0
cbuf.setLength(0)

val defdecl: DefaultDecl = ch match {
case '\'' | '"' =>
Expand All @@ -846,7 +846,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests {
xSpaceOpt()

attList ::= AttrDecl(aname, atpe, defdecl)
cbuf.length = 0
cbuf.setLength(0)
}
nextch()
handle.attListDecl(n, attList.reverse)
Expand Down
Loading

0 comments on commit e02c2be

Please sign in to comment.