-
Notifications
You must be signed in to change notification settings - Fork 122
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
Various modernizations in humminbird. #1100
base: master
Are you sure you want to change the base?
Conversation
robertlipe
commented
May 6, 2023
- Make humminbird_icons[] a QStringList.
- Various attempts to reduce extra allocations and hope that Qt template magic can
- reduce some of those pointer/len buffer move when deailing with those fixed (not zero-terminated) buffers.
- Try to more clearly mark when arrays represent fixed buffers on device files. I don't think the icon finder ever actually worked the way it was described in the comments.
- Make humminbird_icons[] a QStringList. - Various attempts to reduce extra allocations and hope that Qt template magic can - reduce some of those pointer/len buffer move when deailing with those fixed (not zero-terminated) buffers. - Try to more clearly mark when arrays represent fixed buffers on device files. I don't think the icon finder ever actually worked the way it was described in the comments.
Coverage summary from CodacyMerging #1100 (5bf2c0e) into
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
humminbird.h
Outdated
@@ -48,7 +49,7 @@ class HumminbirdBase | |||
|
|||
/* Constants */ | |||
|
|||
static constexpr const char* humminbird_icons[] = { | |||
QStringList humminbird_icons = { |
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 would recommend this be a const QStringList. That avoids any checks for detachment as well as alleviates the need to use qAsConst with this list, so you save the two uses you added in humminbird.cc as well.
humminbird.cc
Outdated
QByteArray ba = QByteArray(w.name, sizeof(w.name)); | ||
wpt->shortname = QString(ba).remove(QChar::Null); |
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.
Can this be
auto ba = QByteArray(w.name, qstrnlen(w.name, sizeof(w.name));
?
If so there are 2 more occurrences of this pattern below.
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.
or better
wpt->shortname = QByteArray(w.name, qstrnlen(w.name, sizeof(w.name));
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! That case of having NO terminator kept haunting me. I wasn't happen with what I landed on (too many type conversions, too many many iterations over the buffer) but this is better.
I actually looked for a qnstrlen but not a qstrnlen. I see now you used this basic approach in garmin.cc where we have that same edge between fixed length, not terminated, buffers and QStrings. Experience!