-
Notifications
You must be signed in to change notification settings - Fork 16
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
[Test.cpp] Optimize size #97
Open
hsaturn
wants to merge
1
commit into
bxparks:develop
Choose a base branch
from
hsaturn:pr
base: develop
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
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.
Good attempt, but now the behavior is subtly different when
mStatus == Test::kStatusUnknown
, right? The current code prints nothing, but your code now prints "Test ", without a trailing newline, which I think is a bit worse. The code duplication should be inconsequential on a desktop, so the memory savings is relevant only to an 8-bit processor, and I think even there, I think the flash memory savings will amount to about 3 x (10-15) bytes, or about 30-50 bytes.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.
Yes ... and this is exactly why you should use enum instead of const ints. The compiler sends a warning when unused enums are not in any case.
This is exactly what I'm doing for AUnitPC (I'm gonna rename it with this name I guess).
edit: I've finished to group many unrelated const uint8_t into three enum classes
You may have a look to LifeCycle and Verbosity that should apply as they are.
For Status, I've changed Test::resolve() a way you may not like.
I prefer a lot to have enum classes because compiler will report an error when one tries to mix together values that are not related.
LifeCycle : hsaturn@1fe7947
Verbosity: hsaturn@741c164
Status: hsaturn@58f0ca8
Important note : I've not regenerated the doc after each commit, instead sed -i have changed the names of the constants, ugly.
The documentation once regenerated is pretty cool with enums 👍

Constants are grouped by function instead of mixed together. Here is what I have for the Status:
Regards
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.
By the way, doing the changes, I've found that kStatusDone in documentation does not exists. Same for kStatusSetup if I'm not wrong.
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.
enum class is probably safer, but I created AUnit before I learned about it, and I didn't have motivation to go back to this, since most (if not all) of this is internal and not exposed to the end-user except through the Failed/Passed status messages. The
LifeCycle
andStatus
variables actually started as a single variable, and only later did it occur to me that it makes more sense to split them, so there might be some residual commingling between them.Funny thing about
enum class
, when I learned about it, I started using it, then I started to find them a bit annoying and unergonomic, so I found myself slowly shifting back to using juststatic constexpr
for internal things. I don't know, I've started to write more C and Golang, and neither of them have enums, so I guess they caused a shift in my thinking process. I think it's all part of my "C++ has too much syntax and cognitive overhead" annoyance.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.
Correction: C has
enum
, notenum class
, but if I recall, C-enum is in the global namespace and doesn't introduce a new type, so basically the same as anint