Skip to content

Commit

Permalink
Retroactive attempt to establish a baseline including the new benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWSpence committed Dec 22, 2023
1 parent 702ab8b commit b08196e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
5 changes: 0 additions & 5 deletions core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,6 @@ sealed abstract private[data] class ChainInstances extends ChainInstances1 {
if (fa.isEmpty) G.pure(Chain.nil)
else
G match {
case x: StackSafeMonad[G] =>
x.map(Traverse.traverseDirectly(fa.iterator)(f)(x))(fromIterableOnce(_))
case _ =>
traverseViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand All @@ -1254,7 +1252,6 @@ sealed abstract private[data] class ChainInstances extends ChainInstances1 {

override def traverse_[G[_], A, B](fa: Chain[A])(f: A => G[B])(implicit G: Applicative[G]): G[Unit] =
G match {
case x: StackSafeMonad[G] => Traverse.traverse_Directly(fa.iterator)(f)(x)
case _ =>
foldRight(fa, Always(G.pure(()))) { (a, acc) =>
G.map2Eval(f(a), acc) { (_, _) =>
Expand Down Expand Up @@ -1371,8 +1368,6 @@ sealed abstract private[data] class ChainInstances extends ChainInstances1 {
if (fa.isEmpty) G.pure(Chain.nil)
else
G match {
case x: StackSafeMonad[G] =>
x.map(TraverseFilter.traverseFilterDirectly(fa.iterator)(f)(x))(traverse.fromIterableOnce(_))
case _ =>
traverseFilterViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/scala/cats/instances/list.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package cats
package instances

import cats.data.{Chain, Ior, ZipList}
import cats.StackSafeMonad
import cats.instances.StaticMethods.appendAll
import cats.kernel.compat.scalaVersionSpecific._
import cats.kernel.instances.StaticMethods.wrapMutableIndexedSeq
Expand Down Expand Up @@ -122,7 +121,6 @@ trait ListInstances extends cats.kernel.instances.ListInstances {
if (fa.isEmpty) G.pure(Nil)
else
G match {
case x: StackSafeMonad[G] => x.map(Traverse.traverseDirectly[G, A, B](fa)(f)(x))(_.toList)
case _ =>
G.map(Chain.traverseViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand All @@ -136,8 +134,7 @@ trait ListInstances extends cats.kernel.instances.ListInstances {
*/
override def traverse_[G[_], A, B](fa: List[A])(f: A => G[B])(implicit G: Applicative[G]): G[Unit] = {
G match {
case x: StackSafeMonad[G] => Traverse.traverse_Directly(fa)(f)(x)
case _ =>
case _ =>
// the cost of this is O(size log size)
// c(n) = n + 2 * c(n/2) = n + 2(n/2 log (n/2)) = n + n (logn - 1) = n log n
// invariant: size >= 1
Expand Down Expand Up @@ -320,7 +317,6 @@ private[instances] trait ListInstancesBinCompat0 {
if (fa.isEmpty) G.pure(Nil)
else
G match {
case x: StackSafeMonad[G] => x.map(TraverseFilter.traverseFilterDirectly(fa)(f)(x))(_.toList)
case _ =>
G.map(Chain.traverseFilterViaChain {
val as = collection.mutable.ArrayBuffer[A]()
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/scala/cats/instances/vector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ trait VectorInstances extends cats.kernel.instances.VectorInstances {

final override def traverse[G[_], A, B](fa: Vector[A])(f: A => G[B])(implicit G: Applicative[G]): G[Vector[B]] =
G match {
case x: StackSafeMonad[G] => x.map(Traverse.traverseDirectly(fa)(f)(x))(_.toVector)
case _ => G.map(Chain.traverseViaChain(fa)(f))(_.toVector)
case _ => G.map(Chain.traverseViaChain(fa)(f))(_.toVector)
}

final override def updated_[A, B >: A](fa: Vector[A], idx: Long, b: B): Option[Vector[B]] =
Expand All @@ -142,8 +141,7 @@ trait VectorInstances extends cats.kernel.instances.VectorInstances {
*/
override def traverse_[G[_], A, B](fa: Vector[A])(f: A => G[B])(implicit G: Applicative[G]): G[Unit] = {
G match {
case x: StackSafeMonad[G] => Traverse.traverse_Directly(fa)(f)(x)
case _ =>
case _ =>
// the cost of this is O(size)
// c(n) = 1 + 2 * c(n/2)
// invariant: size >= 1
Expand Down Expand Up @@ -271,7 +269,6 @@ private[instances] trait VectorInstancesBinCompat0 {

def traverseFilter[G[_], A, B](fa: Vector[A])(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[Vector[B]] =
G match {
case x: StackSafeMonad[G] => TraverseFilter.traverseFilterDirectly(fa)(f)(x)
case _ =>
G.map(Chain.traverseFilterViaChain(fa)(f))(_.toVector)
}
Expand Down

0 comments on commit b08196e

Please sign in to comment.