-
Notifications
You must be signed in to change notification settings - Fork 3k
Reduce Callback.h using C++11 #10885
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
Conversation
The bulk of Callback.h was auto-generated as 6 specialisations, handling zero to five arguments. This can now be handled without specialisation using C++11 variadic templates, reducing the file from 4,900 lines to 900 lines. This should reduce compilation time, and offset potential increases from use of `<type_traits>` or a local `mbed_cxxsupport.h` equivalent. Several other improvents to `Callback` are possible and/or desirable with C++11, such as the ability to store lambdas, but this commit is purely the variadic simplification.
The header file is actually somewhat understandable after this - it is complex, but the previous version further obfuscated it by just repeating everything 6 times, meaning it was rather hard to visualise the structure. C++11 could possibly simplify it further using type traits to cut out a bunch of the const/volatile overloading repetition. |
Could get it down to 500 lines if all the deprecated stuff was dropped... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look goods to me.
I've been working on a new implementation yesterday, that reduces the code size and simplify most of the (unnecessary) overloads and add other goodies. I will submit it once this first simplification goes in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great, thanks Kevin!
I was discussing with the team this optimisation just a few days ago as this file was really huge! Did not know that you had plan to work on it :)
Cool. I'll hold off on my temptation to fiddle further then, and wait to review yours. |
@evedon events/Event.h would also benefit from such simplification. |
It would make sense to do the same thing to Event.h at the same time. I can do that now, if no-one else has already done it. |
We have not worked on it so feel free. |
Hmm, Event.h and EventQueue.h are much more complex, as they don't just have to forward variadic arguments, they have to store them (in the |
In that case, it is not worth doing it as part of this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to see this come in 👍
No doubt this was what you were yearning to write in the first place. The hard part was generating the C++98 version!
Actually, they're not so bad. I think I can remove 95% of them - it's just the innermost |
@kjbracey-arm , what is status of this PR? |
I think it's ready. Got a pile of design changes to follow, but this one's fine. |
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
The bulk of Callback.h was auto-generated as 6 specialisations, handling zero to five arguments.
This can now be handled without specialisation using C++11 variadic templates, reducing the file from 4,900 lines to 900 lines.
This should reduce compilation time, and offset potential increases from use of
<type_traits>
or a localmbed_cxxsupport.h
equivalent.Several other improvents to
Callback
are possible and/or desirable with C++11, such as the ability to store lambdas, but this commit is purely the variadic simplification.Pull request type
Reviewers
@pan-, @bulislaw, @geky