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 827edfb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions project/MimaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ 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"),
)

override val buildSettings = Seq(
Expand Down
8 changes: 7 additions & 1 deletion src/library/scala/concurrent/impl/FutureConvertersImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,17 @@ 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] {
final class P[T](val wrapped: CompletionStage[T]) extends DefaultPromise[T] with BiConsumer[T, Throwable]
with BiFunction[T, Throwable, Unit] {
override def accept(v: T, e: Throwable): Unit = {
if (e == null) success(v)
else failure(e)
}

override def apply(v: T, e: Throwable): Unit = {
if (e == null) success(v)
else failure(e)
}
}
}

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 827edfb

Please sign in to comment.