Skip to content
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

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

guizmaii
Copy link
Member

No description provided.

@guizmaii guizmaii requested a review from a team as a code owner August 12, 2024 10:02
@@ -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
Copy link
Contributor

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 }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed this.

@guizmaii
Copy link
Member Author

@kyri-petrou Thanks for your review. I updated the PR

Copy link
Contributor

@kyri-petrou kyri-petrou left a 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

@guizmaii guizmaii merged commit 7236421 into series/2.x Aug 13, 2024
20 of 21 checks passed
@guizmaii guizmaii deleted the validation branch August 13, 2024 08:58
@guizmaii
Copy link
Member Author

Thanks @kyri-petrou @sideeffffect 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants