Skip to content

Commit

Permalink
=lib Make use of CompletionStage#handle instead of CompletionStage#wh…
Browse files Browse the repository at this point in the history
…enComplete for better performance.
  • Loading branch information
He-Pin committed Oct 8, 2022
1 parent cd52542 commit fbbc998
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions project/MimaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ object MimaFilters extends AutoPlugin {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.Predef#ArrayCharSequence.isEmpty"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.ArrayCharSequence.isEmpty"),

// KEEP: make use of CompletionStage#handle to get a better performance than CompletionStage#whenComplete.
ProblemFilters.exclude[MissingTypesProblem]("scala.concurrent.impl.FutureConvertersImpl$P"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.concurrent.impl.FutureConvertersImpl#P.andThen"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.concurrent.impl.FutureConvertersImpl#P.apply"),
ProblemFilters.exclude[IncompatibleMethTypeProblem]("scala.concurrent.impl.FutureConvertersImpl#P.andThen"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.concurrent.impl.FutureConvertersImpl#P.accept"),
ProblemFilters.exclude[IncompatibleMethTypeProblem]("scala.concurrent.impl.FutureConvertersImpl#P.andThen"),
)

override val buildSettings = Seq(
Expand Down
4 changes: 2 additions & 2 deletions src/library/scala/concurrent/impl/FutureConvertersImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private[scala] object FutureConvertersImpl {
override def toString(): String = super[CompletableFuture].toString
}

final class P[T](val wrapped: CompletionStage[T]) extends DefaultPromise[T] with BiConsumer[T, Throwable] {
override def accept(v: T, e: Throwable): Unit = {
final class P[T](val wrapped: CompletionStage[T]) extends DefaultPromise[T] with BiFunction[T, Throwable, Unit] {
override def apply(v: T, e: Throwable): Unit = {
if (e == null) success(v)
else failure(e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/jdk/javaapi/FutureConverters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ object FutureConverters {
case f: Future[T @unchecked] => f
case _ =>
val p = new P[T](cs)
cs whenComplete p
cs.handle(p)
p.future
}
}
Expand Down

0 comments on commit fbbc998

Please sign in to comment.