Skip to content

Refactor DebugCount#6753

Merged
pajlada merged 11 commits intomasterfrom
chore/refactor-debugcount
Jan 28, 2026
Merged

Refactor DebugCount#6753
pajlada merged 11 commits intomasterfrom
chore/refactor-debugcount

Conversation

@Mm2PL
Copy link
Copy Markdown
Collaborator

@Mm2PL Mm2PL commented Jan 19, 2026

Switching to enums gives us a nice way to implement a base template that increments and decrements the DebugCount on (de)construction.

This fixes issues with Lua HTTP objects showing negative amounts, I don't believe we had an issue for that. I undid the AutoDebugCount changes.

@Mm2PL Mm2PL force-pushed the chore/refactor-debugcount branch from 066383c to 10cceb5 Compare January 19, 2026 17:36
@Mm2PL Mm2PL requested a review from pajlada January 20, 2026 01:08
Comment thread src/util/DebugCount.cpp
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/messages/Image.cpp
DebugCount::set("last image gc: expired", numExpired);
DebugCount::set("last image gc: eligible", eligible);
DebugCount::set("last image gc: left after gc", this->allImages_.size());
DebugCount::set(DebugObject::LastImageGcExpired, numExpired);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int64_t' (aka 'long') is implementation-defined [bugprone-narrowing-conversions]

    DebugCount::set(DebugObject::LastImageGcExpired, numExpired);
                                                     ^

Comment thread src/messages/Image.cpp
DebugCount::set("last image gc: eligible", eligible);
DebugCount::set("last image gc: left after gc", this->allImages_.size());
DebugCount::set(DebugObject::LastImageGcExpired, numExpired);
DebugCount::set(DebugObject::LastImageGcEligible, eligible);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int64_t' (aka 'long') is implementation-defined [bugprone-narrowing-conversions]

    DebugCount::set(DebugObject::LastImageGcEligible, eligible);
                                                      ^

Comment thread src/messages/Image.cpp
DebugCount::set("last image gc: left after gc", this->allImages_.size());
DebugCount::set(DebugObject::LastImageGcExpired, numExpired);
DebugCount::set(DebugObject::LastImageGcEligible, eligible);
DebugCount::set(DebugObject::LastImageGcLeft, this->allImages_.size());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: narrowing conversion from 'size_type' (aka 'unsigned long') to signed type 'int64_t' (aka 'long') is implementation-defined [bugprone-narrowing-conversions]

    DebugCount::set(DebugObject::LastImageGcLeft, this->allImages_.size());
                                                  ^

Comment thread src/util/DebugCount.cpp
Comment thread src/util/DebugCount.cpp Outdated

namespace chatterino {

void DebugCount::set(DebugObject target, const int64_t &amount)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: chatterino::DebugCount::set: Pass small and trivially-copyable type by value (const int64_t & amount) [clazy-function-args-by-value]

Suggested change
void DebugCount::set(DebugObject target, const int64_t &amount)
void DebugCount::set(DebugObject target, int64_t amount)

src/util/DebugCount.hpp:60:

-     static void set(DebugObject target, const int64_t &amount);
+     static void set(DebugObject target, int64_t amount);

Comment thread src/util/DebugCount.cpp Outdated
}

void DebugCount::decrease(const QString &name, const int64_t &amount)
void DebugCount::decrease(DebugObject target, const int64_t &amount)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: chatterino::DebugCount::decrease: Pass small and trivially-copyable type by value (const int64_t & amount) [clazy-function-args-by-value]

Suggested change
void DebugCount::decrease(DebugObject target, const int64_t &amount)
void DebugCount::decrease(DebugObject target, int64_t amount)

src/util/DebugCount.hpp:68:

-     static void decrease(DebugObject target, const int64_t &amount);
+     static void decrease(DebugObject target, int64_t amount);

Comment thread src/util/DebugCount.hpp

namespace chatterino {

enum class DebugObject : size_t {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: enum 'DebugObject' uses a larger base type ('size_t' (aka 'unsigned long'), size: 8 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

enum class DebugObject : size_t {
           ^

Comment thread src/util/DebugCount.hpp Outdated
Comment thread src/util/DebugCount.hpp
Comment thread src/util/DebugCount.hpp
case chatterino::DebugObject::MessageThread:
case chatterino::DebugObject::Message:
default:
return default_tag;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: Using copy-ctor but class magic_enum::customize::customize_t has a trivial copy-ctor but non trivial assign operator [clazy-rule-of-two-soft]

            return default_tag;
                   ^

Copy link
Copy Markdown
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to apply the clang-tidy suggestions about const& params on the set calls

Comment thread src/util/DebugCount.hpp Outdated

static void set(const QString &name, const int64_t &amount);
template <DebugObject target>
class AutoDebugCount
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we hold off on the AutoDebugCount implementation for a follow-up PR?

Comment thread src/util/DebugCount.cpp

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
UniqueAccess<std::map<QString, Count>> COUNTS;
UniqueAccess<std::array<Count, static_cast<size_t>(DebugObject::Count)>> COUNTS;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can make use of magic_enum's enum_size function here, which means we don't have to keep Count

Comment thread src/util/DebugCount.hpp
};

} // namespace chatterino
template <>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Suggested change
template <>
template <>

@Mm2PL
Copy link
Copy Markdown
Collaborator Author

Mm2PL commented Jan 24, 2026 via email

@Mm2PL Mm2PL force-pushed the chore/refactor-debugcount branch from 68dceef to 65eb043 Compare January 27, 2026 21:25
Comment thread src/util/DebugCount.hpp
Comment on lines +63 to +64
static void increase(DebugObject target, int64_t amount);
static void increase(DebugObject target)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The amount could default to 1, then you won't need an additional overload. Same for the decrease method.

@pajlada pajlada enabled auto-merge (squash) January 28, 2026 10:14
@pajlada pajlada merged commit 60ecf1a into master Jan 28, 2026
19 checks passed
@pajlada pajlada deleted the chore/refactor-debugcount branch January 28, 2026 10:37
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.

3 participants