8000 Small fixes and more tests for jdk Converters by lrytz · Pull Request #7970 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Small fixes and more tests for jdk Converters #7970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test for Steppers
There are a few open issues
  - ChampStepper doesn't return all elements (Rex is working on a fix)
  - TableStepper.trySplit has a bug, it was changed to always return
    `null` in a previous commit (Rex is also fixing this)
  - The `ORDERED` flag is often not correct, in particular when creating
    a Stepper of a Set, and there's no specific implementation. Then
    the implementation falls back to IterableOnce, and IteratorStepper
    has the `ORDERED` flag
  • Loading branch information
lrytz committed Apr 12, 2019
commit 12e525beb4515e1df08e5b42dbd43dac20b99ccd
6 changes: 6 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ val mimaPrereleaseHandlingSettings = Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.StreamExtensions.CharArrayHasSeqParStream"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.StreamExtensions.ByteArrayHasSeqParStream"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.StreamExtensions.FloatArrayHasSeqParStream"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.StepperShape$"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.StepperShape$"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.StepperShapeLowPriority"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.StepperShapeLowPriority1"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.StepperShapeLowPriority2"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.StepperShape.anyStepperShapePrototype"),
),
)

Expand Down
12 changes: 8 additions & 4 deletions src/library/scala/collection/StepperShape.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sealed trait StepperShape[T, S <: Stepper[_]] {
def parUnbox(st: AnyStepper[T] with EfficientSplit): S with EfficientSplit
}

object StepperShape extends StepperShapeLowPriority {
object StepperShape extends StepperShapeLowPriority1 {
class Shape private[StepperShape] (private val s: Int) extends AnyVal

// reference
Expand Down Expand Up @@ -84,12 +84,16 @@ object StepperShape extends StepperShapeLowPriority {
}
}

trait StepperShapeLowPriority {
trait StepperShapeLowPriority1 extends StepperShapeLowPriority2 {
implicit def anyStepperShape[T]: StepperShape[T, AnyStepper[T]] = anyStepperShapePrototype.asInstanceOf[StepperShape[T, AnyStepper[T]]]
}

trait StepperShapeLowPriority2 {
implicit def baseStepperShape[T]: StepperShape[T, Stepper[T]] = anyStepperShapePrototype.asInstanceOf[StepperShape[T, Stepper[T]]]

private[this] val anyStepperShapePrototype: StepperShape[AnyRef, AnyStepper[AnyRef]] = new StepperShape[AnyRef, AnyStepper[AnyRef]] {
protected val anyStepperShapePrototype: StepperShape[AnyRef, Stepper[AnyRef]] = new StepperShape[AnyRef, Stepper[AnyRef]] {
def shape = StepperShape.ReferenceShape
def seqUnbox(st: AnyStepper[AnyRef]): AnyStepper[AnyRef] = st
def parUnbox(st: AnyStepper[AnyRef] with EfficientSplit): AnyStepper[AnyRef] with EfficientSplit = st
}
}
}
7 changes: 4 additions & 3 deletions src/library/scala/collection/convert/StreamExtensions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

package scala.collection.convert

import java.util.Spliterator
import java.util.stream._

import scala.annotation.implicitNotFound
Expand Down Expand Up @@ -389,10 +390,10 @@ object StreamExtensions {

trait StreamShapeLowPriority2 {
// reference
implicit def anyStreamShape[T]: StreamShape[T, Stream[T], AnyStepper[T]] = anyStreamShapePrototype.asInstanceOf[StreamShape[T, Stream[T], AnyStepper[T]]]
implicit def anyStreamShape[T]: StreamShape[T, Stream[T], Stepper[T]] = anyStreamShapePrototype.asInstanceOf[StreamShape[T, Stream[T], Stepper[T]]]

private[this] val anyStreamShapePrototype: StreamShape[AnyRef, Stream[AnyRef], AnyStepper[AnyRef]] = new StreamShape[AnyRef, Stream[AnyRef], AnyStepper[AnyRef]] {
def mkStream(s: AnyStepper[AnyRef], par: Boolean): Stream[AnyRef] = StreamSupport.stream(s.spliterator, par)
private[this] val anyStreamShapePrototype: StreamShape[AnyRef, Stream[AnyRef], Stepper[AnyRef]] = new StreamShape[AnyRef, Stream[AnyRef], Stepper[AnyRef]] {
def mkStream(s: Stepper[AnyRef], par: Boolean): Stream[AnyRef] = StreamSupport.stream(s.spliterator.asInstanceOf[Spliterator[AnyRef]], par)
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/library/scala/collection/immutable/WrappedString.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package scala.collection
package immutable

import scala.Predef.{wrapString => _}
import scala.Predef.{wrapString => _, assert}
import scala.collection.Stepper.EfficientSplit
import scala.collection.convert.impl.CharStringStepper
import scala.collection.mutable.{Builder, StringBuilder}
Expand Down Expand Up @@ -55,8 +55,16 @@ final class WrappedString(private val self: String) extends AbstractSeq[Char] wi
override def toString = self
override def view: StringView = new StringView(self)

override def stepper[B >: Char, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit =
(new CharStringStepper(self, 0, self.length)).asInstanceOf[S with EfficientSplit]
override def stepper[B >: Char, S <: Stepper[_]](implicit shape: StepperShape[B, S]): S with EfficientSplit = {
val st = new CharStringStepper(self, 0, self.length)
val r =
if (shape.shape == StepperShape.CharShape) st
else {
assert(shape.shape == StepperShape.ReferenceShape, s"unexpected StepperShape: $shape")
AnyStepper.ofParIntStepper(st)
}
r.asInstanceOf[S with EfficientSplit]
}

override def startsWith[B >: Char](that: IterableOnce[B], offset: Int = 0): Boolean =
that match {
Expand Down
Loading
0