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 unnecessary shared_ptr copies and simplify static initialization #505

Merged
merged 1 commit into from
Sep 3, 2022

Conversation

vittorioromeo
Copy link
Contributor

@vittorioromeo vittorioromeo commented Aug 23, 2022

Untested, but the behaviour should be the same unless I am missing something. Basically, I've changed some auto to auto& to avoid an unnecessary std::shared_ptr copy, and also simplified the initialization of some static function-scope variables, as I don't think that an extra check was needed (again, unless I am missing something).

Will likely have no significant impact on performance but if many std::shared_ptr copies were being unnecessarily made per-frame then it might actually reduce CPU usage a bit.

Also, (again -- I might be missing something), all of these ::get() functions maybe do not even need shared pointers at all. E.g. how about:

RE8VR& RE8VR::get() {
    static RE8VR inst;
    return inst;
}

?

@praydog
Copy link
Owner

praydog commented Sep 3, 2022

Tested it for a bit in MHRise with a bunch of scripts & then with VR loaded, did not notice any bugs. Thanks for the PR.

I'm not super against refactoring the ::get() functions to return a reference to a static as long as nothing is broken still.

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.

2 participants