<commit_before>#pragma once
#include <Data/RefCounted.h>
#include <Events/EventsFwd.h>

// Abstract wrapper for different event callback types

namespace Events
{

// NB: refcounting is required for unsubscribing from an event inside its handler
class CEventHandler: public Data::CRefCounted
{
protected:

	U16 Priority;

public:

	virtual ~CEventHandler() override = default;

	PEventHandler Next;

	CEventHandler(U16 _Priority = Priority_Default): Priority(_Priority) {}

	U16          GetPriority() const { return Priority; }
	virtual bool Invoke(CEventDispatcher* pDispatcher, const CEventBase& Event) = 0;
<commit_msg>More compact refcounter for event handlers<commit_after>#pragma once
#include <Data/RefCounted.h>
#include <Events/EventsFwd.h>

// Abstract wrapper for different event callback types

namespace Events
{

// NB: refcounting is required for unsubscribing from an event inside its handler
class CEventHandler
{
protected:

	U16 RefCount = 0;
	U16 Priority;

	friend inline void DEMPtrAddRef(Events::CEventHandler* p) noexcept { ++p->RefCount; }
	friend inline void DEMPtrRelease(Events::CEventHandler* p) noexcept { n_assert_dbg(p->RefCount > 0); if (--p->RefCount == 0) n_delete(p); }

public:

	virtual ~CEventHandler() = default;

	PEventHandler Next;

	CEventHandler(U16 _Priority = Priority_Default): Priority(_Priority) {}

	U16          GetPriority() const { return Priority; }
	virtual bool Invoke(CEventDispatcher* pDispatcher, const CEventBase& Event) = 0;

{'fraction_non_alphanumeric': 0.09475806451612903, 'fraction_numerical': 0.012768817204301076, 'mean_word_length': 5.178423236514523, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5428581', 'n_tokens_mistral': 473, 'n_tokens_neox': 440, 'n_words': 140}