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

Remove functional include and use unique_ptr more efficiently #76

Merged

Conversation

jens-diewald
Copy link
Contributor

A technicality i came across while looking through the code.
If a unique_ptr type is always used with the same deleter function, it should be part of the deleter type instead of using function pointers or even std::function.
This has the advantage, that we do not have to repeat the deleter function for every instantiation and it is also a little more efficient, as not every unique_ptr has to save the additional function pointer or function object within it. (sizeof(cert_context_ptr) is now 8 and was 16 before.)

<functional> is a heavy dependency regarding compile time
and std::function may also introduce a small runtime overhead
over a raw function pointer
A deleter which is a function pointer has to be stored within the unique_ptr.
Using a separate deleter type removes that overhead
and also the need to specify the deleter function at every instantiation
of the unique_ptr type.
@laudrup
Copy link
Owner

laudrup commented Jan 6, 2023

Sorry, I had completely forgotten about this.

Looks really great. Thanks a lot for your contribution.

@laudrup laudrup merged commit 9665818 into laudrup:master Jan 6, 2023
@jens-diewald jens-diewald deleted the remove-functional-refactor_unique_ptr branch March 8, 2023 19:19
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