Skip to content

Commit

Permalink
remove 'collection.breakOut'
Browse files Browse the repository at this point in the history
The performances stay similar
  • Loading branch information
yanns committed Mar 20, 2019
1 parent b5f38d5 commit 598f940
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions benchmarks/src/main/scala/json/ToJsonBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class ToJsonBenchmark {
/* on local mac
jmh:run
Benchmark Mode Cnt Score Error Units
ToJsonBenchmark.listWriter thrpt 10 70,065 ± 0,967 ops/s
ToJsonBenchmark.seqWriter thrpt 10 63,512 ± 3,889 ops/s
ToJsonBenchmark.serializeCaseClassToString thrpt 10 37,925 ± 2,252 ops/s
ToJsonBenchmark.vectorWriter thrpt 10 63,762 ± 1,470 ops/s
Benchmark Mode Cnt Score Error Units
ToJsonBenchmark.listWriter thrpt 10 68,770 ± 1,157 ops/s
ToJsonBenchmark.seqWriter thrpt 10 65,792 ± 1,191 ops/s
ToJsonBenchmark.serializeCaseClassToString thrpt 10 39,142 ± 0,574 ops/s
ToJsonBenchmark.vectorWriter thrpt 10 64,359 ± 2,162 ops/s
*/

@Benchmark
Expand Down
11 changes: 6 additions & 5 deletions json/src/main/scala/io/sphere/json/ToJSON.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.sphere.json

import cats.data.NonEmptyList

import scala.collection.breakOut
import java.util.{Currency, Locale, UUID}

import io.sphere.util.{BaseMoney, HighPrecisionMoney, Money}
Expand Down Expand Up @@ -44,15 +43,17 @@ object ToJSON {
}

implicit def seqWriter[@specialized A](implicit w: ToJSON[A]): ToJSON[Seq[A]] = new ToJSON[Seq[A]] {
def write(s: Seq[A]): JValue = JArray(s.map(w.write)(breakOut))
def write(s: Seq[A]): JValue = JArray(s.iterator.map(w.write).toList)
}

implicit def setWriter[@specialized A](implicit w: ToJSON[A]): ToJSON[Set[A]] = new ToJSON[Set[A]] {
def write(s: Set[A]): JValue = JArray(s.map(w.write)(breakOut))
def write(s: Set[A]): JValue = JArray(s.iterator.map(w.write).toList)
}

implicit def vectorWriter[@specialized A](implicit w: ToJSON[A]): ToJSON[Vector[A]] = new ToJSON[Vector[A]] {
def write(v: Vector[A]): JValue = JArray(v.map(w.write)(breakOut))
def write(v: Vector[A]): JValue = {
JArray(v.iterator.map(w.write).toList)
}
}

implicit val intWriter: ToJSON[Int] = new ToJSON[Int] {
Expand Down Expand Up @@ -88,7 +89,7 @@ object ToJSON {
}

implicit def mapWriter[A: ToJSON]: ToJSON[Map[String, A]] = new ToJSON[Map[String, A]] {
def write(m: Map[String, A]) = JObject(m.map { case (k, v) => JField(k, toJValue(v)) }(breakOut): _*)
def write(m: Map[String, A]) = JObject(m.iterator.map { case (k, v) => JField(k, toJValue(v)) }.toList)
}

implicit val moneyWriter: ToJSON[Money] = new ToJSON[Money] {
Expand Down
3 changes: 2 additions & 1 deletion util/src/main/scala/Reflect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object Reflect extends Logging {
}

sym.children
.iterator
.collect { case m: MethodSymbol if m.isCaseAccessor && !m.isPrivate => m }
.zipWithIndex
.map { case (ms, idx) =>
Expand All @@ -52,7 +53,7 @@ object Reflect extends Logging {
case _: NoSuchMethodException => None
}
CaseClassFieldMeta(ms.name, defaultValue)
}(collection.breakOut)
}.toIndexedSeq
}
}
}

0 comments on commit 598f940

Please sign in to comment.