Skip to content

Commit 24f61c0

Browse files
authored
Merge pull request #580 from plokhotnyuk/scala3
More efficient evaluation of default values
2 parents 08c224f + 713168d commit 24f61c0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/src/main/scala/magnolia1/impl.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,10 @@ object CaseClassDerivation:
117117
new SerializableFunction0[Option[p]]:
118118
override def apply(): Option[p] =
119119
val v = evaluator()
120-
if ((v: @unchecked).isInstanceOf[p]) Some(v.asInstanceOf[p])
120+
if ((v: @unchecked).isInstanceOf[p]) new Some(v).asInstanceOf[Option[p]]
121121
else None
122122
case _ =>
123-
new SerializableFunction0[Option[p]]:
124-
override def apply(): Option[p] = None
123+
returningNone.asInstanceOf[SerializableFunction0[Option[p]]]
125124
}
126125
paramFromMaps[Typeclass, A, p](
127126
label,
@@ -163,6 +162,10 @@ object CaseClassDerivation:
163162
IArray.from(typeAnnotations.getOrElse(label, List()))
164163
)
165164

165+
private val returningNone =
166+
new SerializableFunction0[Option[Any]]:
167+
override def apply(): Option[Any] = None
168+
166169
end CaseClassDerivation
167170

168171
trait SealedTraitDerivation:

0 commit comments

Comments
 (0)