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

Replace default_callback function with nullptr and check for null… #72

Merged
merged 1 commit into from
May 10, 2015

Conversation

aburgh
Copy link
Contributor

@aburgh aburgh commented May 10, 2015

… callback function before calling it. This is cleaner and better performing.

This is in response to your question about performance and the temporary object for the callback. This does not eliminate the temporary object, but it replaces the default callback with a check for null on the callback member variable, which is faster and avoids the temp object in the default case. In the case where the caller has supplied a callback function, presumably the overhead of a temp object is negligible compared to the processing that will be performed in the callback.

If you would like to optimize the callback to avoid the temp object, the only solution I can think of at the moment is to change the basic_json reference parameter of the callback function to a void * and require the callback function to cast it to a string pointer or basic_json pointer based on the event type. This solution sounds really ugly to me, so my vote is in favor of the temp object.

… callback function before calling it. This is cleaner and better performing.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.87% when pulling ef54ace on aburgh:null-callback into 76d3433 on nlohmann:master.

nlohmann added a commit that referenced this pull request May 10, 2015
Replace `default_callback` function with `nullptr` and check for null…
@nlohmann nlohmann merged commit 072dc25 into nlohmann:master May 10, 2015
@nlohmann
Copy link
Owner

Thanks a lot! That's a few percent performance improvement!

@aburgh aburgh deleted the null-callback branch May 10, 2015 21:47
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