-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
py: clean up some header declarations and make some helper functions inline #18725
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
Open
dpgeorge
wants to merge
8
commits into
micropython:master
Choose a base branch
from
dpgeorge:py-clean-up-some-header-decls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
py: clean up some header declarations and make some helper functions inline #18725
dpgeorge
wants to merge
8
commits into
micropython:master
from
dpgeorge:py-clean-up-some-header-decls
+48
−69
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These macros were added in e11b17c for use with `sys.path` and building import path names, as well as being used by the unix port in 625d08a. But the macro usage for importing was promptly replaced with vstrs in e09ffa1, and eventually for the unix port in 520f356, over 9.5 years ago. So, remove these unused macros. Signed-off-by: Damien George <damien@micropython.org>
This inline helper function has two specific uses so doesn't need to be generally available in `py/obj.h`. Signed-off-by: Damien George <damien@micropython.org>
This is an internal helper function that assumes the argument is of type `mp_obj_fun_bc_t`, so has a better home in `py/objfun.h`. Signed-off-by: Damien George <damien@micropython.org>
And change the argument to `const mp_obj_fun_bc_t *`. This makes it clear that it requires that specific type, rather than a general `mp_obj_t`. Signed-off-by: Damien George <damien@micropython.org>
These helper functions assume their argument is of type `mp_obj_list_t` so they have a better home in `py/objlist.h`. Signed-off-by: Damien George <damien@micropython.org>
3b13d93 to
f924983
Compare
|
Code size report: |
This can be done now these functions are declared in `py/objlist.h`, where the `mp_obj_list_t` struct is defined. This changes code size by -24 bytes on bare-arm, and by -56 bytes on stm32. Signed-off-by: Damien George <damien@micropython.org>
These helper functions assume their argument is of type `mp_obj_tuple_t` so they have a better home in `py/objtuple.h`. Also remove `mp_obj_tuple_hash()` because it doesn't have a corresponding function defined anywhere (nor is it ever used). Signed-off-by: Damien George <damien@micropython.org>
This can be done now that it's declared in `py/objtuple.h`, where the `mp_obj_tuple` struct is defined. This allows much better code generation for users of `mp_obj_tuple_get()` where the caller uses len/items immediately (which is most uses), because the compiler no longer needs to allocate the return values on the stack. Changes code size by -36 bytes on bare-arm and -56 bytes on stm32. Signed-off-by: Damien George <damien@micropython.org>
f924983 to
3bc9eac
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18725 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 171 174 +3
Lines 22298 22298
=======================================
Hits 21937 21937
Misses 361 361 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR cleans up a few header declarations:
py/obj.hto specific headers likepy/objtuple.h(because they are internal helpers more than general API functions)mp_obj_fun_get_name()tomp_obj_fun_bc_get_name()and changes the argument signature to make it clear what the argument must beThen it makes some tuple and list functions inline. That's only possible because their declarations were moved to their respective headers (
py/objtuple.handpy/objlist.h). This reduces code size by 50 to 100 bytes, which is a pretty nice saving.Testing
Built locally. Will also be built and tested by CI.
Trade-offs and Alternatives
There is a little bit of code churn here, but IMO it's worth it to get the code size savings.
Renaming
mp_obj_fun_get_name()tomp_obj_fun_bc_get_name()is also arguably not necessary, but I doubt this is ever used by anyone, it's really an internal helper that shouldn't be used externally to the code inpy/.