-
-
Notifications
You must be signed in to change notification settings - Fork 42.4k
Refactor quantum/command.{c,h} for code size & {read,maintain}ability
#11842
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
d7311b0 to
2d625a7
Compare
2d625a7 to
83bae0b
Compare
|
Travis errored on something unrelated: |
…print_version()` Also undo some damage by clang-format in b624f32
…quences with single `xprintf(…)`
`print_{dec,hex}*(…)` are just `#define`s for `xprintf(…)` anyway.
Each additional `xprintf(…)` costs ~8 bytes: the call instructions,
plus an additional NUL terminator.
This _really_ adds up: this commit saves 814 bytes on my ATmega32.
Made various tweaks to the interface, but still functionally identical. Assume `KC_1`…`KC_0` to be contiguous, and removed `numkey2num(…)` entirely. It was exported in `command.h` by 1a0bac8 for no obvious reason, before which it was `static`. I doubt anyone uses it. `mousekey_console()` is now enabled regardless of `MK_3_SPEED`. Needs fleshing out for things other than the X11 variant though. This commit saves 638 bytes on my ATmega32.
83bae0b to
a6576c5
Compare
|
This mostly looks good, but I would have preferred if the last change a6576c5 were done in a separate PR. |
a6576c5 to
3ec12a5
Compare
Done! |
|
Sorry about that, GitHub decided to delete the |
|
Thank you for your contribution! |
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.
__attribute__ ((weak))
|
Thank you for your contribution! |
| @@ -28,8 +28,7 @@ bool command_extra(uint8_t code); | |||
| bool command_console_extra(uint8_t code); | |||
|
|
|||
| #ifdef COMMAND_ENABLE | |||
| uint8_t numkey2num(uint8_t code); | |||
| bool command_proc(uint8_t code); | |||
| bool command_proc(uint8_t code); | |||
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.
I think clang-format will disagree with this (at least, the version of clang-format that the Docker image uses).
…ty (qmk#11842) * quantum/command.c: coalesce `print()`s in `command_common_help()` & `print_version()` Also undo some damage by clang-format in b624f32 * quantum/command.c: replace `print(…); print_{,val_}{dec,hex}*(…);` sequences with single `xprintf(…)` `print_{dec,hex}*(…)` are just `#define`s for `xprintf(…)` anyway. Each additional `xprintf(…)` costs ~8 bytes: the call instructions, plus an additional NUL terminator. This _really_ adds up: this commit saves 814 bytes on my ATmega32. * quantum/command.c: optimise `mousekey_console()` for size & legibility Made various tweaks to the interface, but still functionally identical. Assume `KC_1`…`KC_0` to be contiguous, and removed `numkey2num(…)` entirely. It was exported in `command.h` by 1a0bac8 for no obvious reason, before which it was `static`. I doubt anyone uses it. `mousekey_console()` is now enabled regardless of `MK_3_SPEED`. Needs fleshing out for things other than the X11 variant though. This commit saves 638 bytes on my ATmega32.
…ty (qmk#11842) * quantum/command.c: coalesce `print()`s in `command_common_help()` & `print_version()` Also undo some damage by clang-format in c3e062c * quantum/command.c: replace `print(…); print_{,val_}{dec,hex}*(…);` sequences with single `xprintf(…)` `print_{dec,hex}*(…)` are just `#define`s for `xprintf(…)` anyway. Each additional `xprintf(…)` costs ~8 bytes: the call instructions, plus an additional NUL terminator. This _really_ adds up: this commit saves 814 bytes on my ATmega32. * quantum/command.c: optimise `mousekey_console()` for size & legibility Made various tweaks to the interface, but still functionally identical. Assume `KC_1`…`KC_0` to be contiguous, and removed `numkey2num(…)` entirely. It was exported in `command.h` by ffc1b68 for no obvious reason, before which it was `static`. I doubt anyone uses it. `mousekey_console()` is now enabled regardless of `MK_3_SPEED`. Needs fleshing out for things other than the X11 variant though. This commit saves 638 bytes on my ATmega32.
I accidentally a huge refactor. (This is part 1 of n.) It improves the code size & {read,maintain}ability significantly.
This PR reduces the firmware size by ~1.5kB on my ATmega32, when built with
CONSOLE_ENABLEandCOMMAND_ENABLEset toyes.If possible, could this PR be merged rather than squashed?
Description
Because the last commit moves
mousekey_console()tomousekey.c(verbatim, trust me :), I recommend reading the penultimate commit separately to see the changes tomousekey_console()itself.Types of Changes
Issues Fixed or Closed by This PR
n/aChecklist
My change requires a change to the documentation.I have updated the documentation accordingly.I have added tests to cover my changes.