Skip to content

Commit d8eb98d

Browse files
committed
perf: avoid double checking value0 Future.
1 parent 360d5da commit d8eb98d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

project/MimaFilters.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object MimaFilters extends AutoPlugin {
1010
object autoImport {
1111
val mimaReferenceVersion = settingKey[Option[String]]("Scala version number to run MiMa against")
1212
}
13+
1314
import autoImport._
1415

1516
override val globalSettings = Seq(
@@ -41,17 +42,20 @@ object MimaFilters extends AutoPlugin {
4142

4243
// KEEP: the CommonErrors object is not a public API
4344
ProblemFilters.exclude[MissingClassProblem]("scala.collection.generic.CommonErrors"),
44-
ProblemFilters.exclude[MissingClassProblem]("scala.collection.generic.CommonErrors$")
45+
ProblemFilters.exclude[MissingClassProblem]("scala.collection.generic.CommonErrors$"),
46+
47+
//ADD: Await#CompletedFuture is not a public API
48+
ProblemFilters.exclude[MissingClassProblem]("scala.concurrent.Await$CompletedFuture$")
4549
)
4650

4751
override val buildSettings = Seq(
4852
mimaFailOnNoPrevious := false, // we opt everything out, knowing we only check library/reflect
4953
)
5054

5155
val mimaSettings: Seq[Setting[_]] = Def.settings(
52-
mimaPreviousArtifacts := mimaReferenceVersion.value.map(organization.value % name.value % _).toSet,
53-
mimaCheckDirection := "both",
54-
mimaBinaryIssueFilters ++= mimaFilters,
55-
// mimaReportSignatureProblems := true, // TODO: enable
56+
mimaPreviousArtifacts := mimaReferenceVersion.value.map(organization.value % name.value % _).toSet,
57+
mimaCheckDirection := "both",
58+
mimaBinaryIssueFilters ++= mimaFilters,
59+
// mimaReportSignatureProblems := true, // TODO: enable
5660
)
5761
}

src/library/scala/concurrent/package.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ package object concurrent {
125125
}
126126

127127
package concurrent {
128+
129+
import scala.util.Try
130+
128131
/**
129132
* This marker trait is used by [[Await]] to ensure that [[Awaitable.ready]] and [[Awaitable.result]]
130133
* are not directly called by user code. An implicit instance of this trait is only available when
@@ -170,7 +173,7 @@ package concurrent {
170173
@throws(classOf[TimeoutException])
171174
@throws(classOf[InterruptedException])
172175
final def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type = awaitable match {
173-
case f: Future[T] if f.isCompleted => awaitable.ready(atMost)(AwaitPermission)
176+
case f: Future[T] if f.isCompleted => awaitable
174177
case _ => blocking(awaitable.ready(atMost)(AwaitPermission))
175178
}
176179

@@ -197,8 +200,12 @@ package concurrent {
197200
@throws(classOf[TimeoutException])
198201
@throws(classOf[InterruptedException])
199202
final def result[T](awaitable: Awaitable[T], atMost: Duration): T = awaitable match {
200-
case f: Future[T] if f.isCompleted => f.result(atMost)(AwaitPermission)
203+
case CompletedFuture(result: Try[T] @unchecked) => result.get
201204
case _ => blocking(awaitable.result(atMost)(AwaitPermission))
202205
}
206+
207+
private final object CompletedFuture {
208+
def unapply[T](f: Future[T]): Option[Try[T]] = f.value
209+
}
203210
}
204211
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy