-
Notifications
You must be signed in to change notification settings - Fork 493
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
NoNewGlobals for SBufStats #1754
base: master
Are you sure you want to change the base?
Conversation
SBufStats & | ||
SBuf::Stats() | ||
{ | ||
static auto *stats = new SBufStats; |
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.
Please apply NoNewGlobals code pattern rather than using a similar but different one:
SBufStats & | |
SBuf::Stats() | |
{ | |
static auto *stats = new SBufStats; | |
auto & | |
SBuf::Stats() | |
{ | |
static const auto stats = new SBufStats(); |
N.B. The same applies to virtually any methods in other PRs that can use that pattern. Reusing that pattern helps improve code quality and reduce review iterations/delays.
@@ -339,7 +339,7 @@ class SBuf | |||
SBuf consume(size_type n = npos); | |||
|
|||
/// gets global statistic information | |||
static const SBufStats& GetStats(); | |||
static const SBufStats & GetStats() { return Stats(); } |
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.
We should not have two class methods named GetStats() and Stats(). The names should tell the two methods apart. This was discussed four days ago in another very similar PR: #1749 (comment). Let's reuse the same approach here:
- Use WriteableStats() name for the new method.
- Use GetStats() to preserve old method callers and use a simpler name for the safer method. This method should have been named Stats(), but we do not need to improve that in this PR.
static const SBufStats & GetStats() { return Stats(); } | |
static const auto &GetStats() { return WriteableStats(); } |
If you prefer to also rename GetStats() to Stats() in this PR, I will support that change as well, but I do not insist on it. Your call.
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.
IIRC the GetStats()
only exists because you insisted on the single caller (mgr dump function) being provided a const
. Statistics objects are generally always writable in Squid so they can be updated by the caller/user code, so calling it WritableStats
is redundant.
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.
Alex: We should not have two class methods named GetStats() and Stats(). The names should tell the two methods apart. This was discussed four days ago in another very similar PR: #1749 (comment). Let's reuse the same approach here
Amos: IIRC the
GetStats()
only exists because you insisted on the single caller (mgr dump function) being provided aconst
. Statistics objects are generally always writable in Squid so they can be updated by the caller/user code, so calling itWritableStats
is redundant.
The response quoted above clearly does not address my concern about PR code/changes.
I do not see "redundancy" in "[Get]Stats() and WriteableStats()" naming scheme. If you reject the proposed solution (mimicking the one developed in #1749), please propose something better than that solution. Hopefully, both PRs (and future PRs!) can use the same overall approach that we can agree on.
Issues found by Coverity scan CID 1554550, 1554554, 1554574,
1554597, 1554604, 1554605, 1554613, 1554626, 1554602.