-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Review ZValidation
code: Remove some non-necessary allocations
#1353
Conversation
@@ -75,8 +75,8 @@ sealed trait ZValidation[+W, +E, +A] { self => | |||
*/ | |||
final def flatMap[W1 >: W, E1 >: E, B](f: A => ZValidation[W1, E1, B]): ZValidation[W1, E1, B] = | |||
self match { | |||
case Failure(w, e) => Failure(w, e) | |||
case Success(w, a) => | |||
case failure @ Failure(_, _) => failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a performance perspective, I think this is probably better as it avoids extracting the case class params:
case failure: Failure[E1, B] => failure
Depending on the scalac flags this might raise a warning (I think if the unchecked
flag is used) , in which case you can do this:
case failure: Failure[E1 @unchecked, B @unchecked] => failure
// Or alias the annotation to reduce boilerplate:
import scala.{ unchecked => uc }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed this.
@kyri-petrou Thanks for your review. I updated the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a super minor comment I missed before. Feel free to ignore, as I think there're probably lots of other places in the codebase to improve this and might be better to do it in a separate PR
Thanks @kyri-petrou @sideeffffect 🙏 |
No description provided.