Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Various modernizations in humminbird. #1100

wants to merge 4 commits into from

Conversation

robertlipe
Copy link
Collaborator

  • 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.
@codacy-production
Copy link

codacy-production bot commented May 6, 2023

Coverage summary from Codacy

Merging #1100 (5bf2c0e) into master (9dccbfc) - See PR on Codacy

Coverage variation Diff coverage
-0.03% 76.19%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (9dccbfc) 24154 16373 67.79%
Head commit (5bf2c0e) 24149 (-5) 16362 (-11) 67.75% (-0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1100) 21 16 76.19%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

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 = {
Copy link
Collaborator

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
Comment on lines 250 to 251
QByteArray ba = QByteArray(w.name, sizeof(w.name));
wpt->shortname = QString(ba).remove(QChar::Null);
Copy link
Collaborator

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.

Copy link
Collaborator

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));

Copy link
Collaborator Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants