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

Avoid using NonFatal.unapply #4282

Merged
merged 1 commit into from
Aug 15, 2022

Conversation

jhnsmth
Copy link
Contributor

@jhnsmth jhnsmth commented Aug 15, 2022

Allows to skip an allocation of Option. It is a tiny micro-optimization, but since it not make code more complicated and less readable, why not ?)

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Thanks! FTR here's the decompiled before/after.

before

    default public <A> F catchNonFatal(Function0<A> a, $less$colon$less<Throwable, E> ev) {
        Object f;
        try {
            f = this.pure(a.apply());
        }
        catch (Throwable throwable) {
            Option<Throwable> option;
            Throwable throwable2 = throwable;
            if (throwable2 == null || (option = NonFatal$.MODULE$.unapply(throwable2)).isEmpty()) {
                throw throwable;
            }
            Throwable e = option.get();
            F f2 = this.raiseError(ev.apply(e));
            f = f2;
        }
        return f;
    }

after

    default public <A> F catchNonFatal(Function0<A> a, $less$colon$less<Throwable, E> ev) {
        Object f;
        try {
            f = this.pure(a.apply());
        }
        catch (Throwable throwable) {
            Throwable throwable2 = throwable;
            if (!NonFatal$.MODULE$.apply(throwable2)) {
                throw throwable;
            }
            F f2 = this.raiseError(ev.apply(throwable2));
            f = f2;
        }
        return f;
    }

@armanbilge armanbilge added this to the 2.9.0 milestone Aug 15, 2022
@armanbilge armanbilge merged commit 83ad02b into typelevel:main Aug 15, 2022
@jhnsmth
Copy link
Contributor Author

jhnsmth commented Aug 17, 2022

@armanbilge thanks very much for decompiled code

@jhnsmth jhnsmth deleted the topic/avoid-nonfatal-unapply branch August 17, 2022 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants