From 90dfdb0e1fa3887a253405d670a2c77dce150bca Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 9 Jan 2023 12:46:00 +0300 Subject: [PATCH] Moved NeverFreedPointer to lib_base. --- Telegram/SourceFiles/core/utils.h | 50 ------------------- .../data/data_abstract_structure.cpp | 4 +- .../inline_bots/inline_bot_layout_item.cpp | 3 +- .../ui/effects/send_action_animations.cpp | 3 +- .../window/themes/window_theme.cpp | 3 +- Telegram/lib_base | 2 +- 6 files changed, 10 insertions(+), 55 deletions(-) diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 55669d75af..37f418e782 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/basic_types.h" #include "base/flags.h" #include "base/algorithm.h" -#include "base/assertion.h" #include "base/bytes.h" #include @@ -181,52 +180,3 @@ static int32 FullArcLength = 360 * 16; static int32 QuarterArcLength = (FullArcLength / 4); static int32 MinArcLength = (FullArcLength / 360); static int32 AlmostFullArcLength = (FullArcLength - MinArcLength); - -// This pointer is used for global non-POD variables that are allocated -// on demand by createIfNull(lambda) and are never automatically freed. -template -class NeverFreedPointer { -public: - NeverFreedPointer() = default; - NeverFreedPointer(const NeverFreedPointer &other) = delete; - NeverFreedPointer &operator=(const NeverFreedPointer &other) = delete; - - template - void createIfNull(Args&&... args) { - if (isNull()) { - reset(new T(std::forward(args)...)); - } - }; - - T *data() const { - return _p; - } - T *release() { - return base::take(_p); - } - void reset(T *p = nullptr) { - delete _p; - _p = p; - } - bool isNull() const { - return data() == nullptr; - } - - void clear() { - reset(); - } - T *operator->() const { - return data(); - } - T &operator*() const { - Assert(!isNull()); - return *data(); - } - explicit operator bool() const { - return !isNull(); - } - -private: - T *_p; - -}; diff --git a/Telegram/SourceFiles/data/data_abstract_structure.cpp b/Telegram/SourceFiles/data/data_abstract_structure.cpp index cea74e588e..aa02c91332 100644 --- a/Telegram/SourceFiles/data/data_abstract_structure.cpp +++ b/Telegram/SourceFiles/data/data_abstract_structure.cpp @@ -7,11 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "data/data_abstract_structure.h" +#include "base/never_freed_pointer.h" + namespace Data { namespace { using DataStructures = OrderedSet; -NeverFreedPointer structures; +base::NeverFreedPointer structures; } // namespace diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp index 17eeeed0bc..1bbaad755e 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "inline_bots/inline_bot_layout_item.h" +#include "base/never_freed_pointer.h" #include "data/data_photo.h" #include "data/data_document.h" #include "data/data_peer.h" @@ -24,7 +25,7 @@ namespace InlineBots { namespace Layout { namespace { -NeverFreedPointer documentItemsMap; +base::NeverFreedPointer documentItemsMap; } // namespace diff --git a/Telegram/SourceFiles/ui/effects/send_action_animations.cpp b/Telegram/SourceFiles/ui/effects/send_action_animations.cpp index 526846e5a9..12fad042d8 100644 --- a/Telegram/SourceFiles/ui/effects/send_action_animations.cpp +++ b/Telegram/SourceFiles/ui/effects/send_action_animations.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/send_action_animations.h" #include "api/api_send_progress.h" +#include "base/never_freed_pointer.h" #include "ui/effects/animation_value.h" #include "ui/painter.h" #include "styles/style_widgets.h" @@ -82,7 +83,7 @@ namespace { using ImplementationsMap = QMap< Api::SendProgressType, const SendActionAnimation::Impl::MetaData*>; -NeverFreedPointer Implementations; +base::NeverFreedPointer Implementations; class TypingAnimation : public SendActionAnimation::Impl { public: diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index c2961f9477..b296da4933 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/zlib_help.h" #include "base/unixtime.h" #include "base/crc32hash.h" +#include "base/never_freed_pointer.h" #include "data/data_session.h" #include "data/data_document_resolver.h" #include "main/main_account.h" // Account::local. @@ -58,7 +59,7 @@ struct Applying { Fn overrideKeep; }; -NeverFreedPointer GlobalBackground; +base::NeverFreedPointer GlobalBackground; Applying GlobalApplying; inline bool AreTestingTheme() { diff --git a/Telegram/lib_base b/Telegram/lib_base index 117b8a248d..1bc41f2cf8 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit 117b8a248d4a74b90b7a3708622a53150f1fe88f +Subproject commit 1bc41f2cf875345c0965687fd8439f83aaa7738a