Skip to content

Commit

Permalink
optimization: avoid NotGiven allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Mar 14, 2023
1 parent 528d931 commit 421591f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/src/scala/util/NotGiven.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ trait LowPriorityNotGiven {
}
object NotGiven extends LowPriorityNotGiven {

private val cachedValue = new NotGiven[Nothing]()

/** A value of type `NotGiven` to signal a successful search for `NotGiven[C]` (i.e. a failing
* search for `C`). A reference to this value will be explicitly constructed by Dotty's
* implicit search algorithm
*/
def value: NotGiven[Nothing] = new NotGiven[Nothing]()
def value: NotGiven[Nothing] = cachedValue

/** One of two ambiguous methods used to emulate negation in Scala 2 */
given amb1[T](using ev: T): NotGiven[T] = ???
Expand Down

0 comments on commit 421591f

Please sign in to comment.