Moved NeverFreedPointer to lib_base.

This commit is contained in:
23rd 2023-01-09 12:46:00 +03:00
parent 7cd330db9a
commit 90dfdb0e1f
6 changed files with 10 additions and 55 deletions

View File

@ -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 <crl/crl_time.h>
@ -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 <typename T>
class NeverFreedPointer {
public:
NeverFreedPointer() = default;
NeverFreedPointer(const NeverFreedPointer<T> &other) = delete;
NeverFreedPointer &operator=(const NeverFreedPointer<T> &other) = delete;
template <typename... Args>
void createIfNull(Args&&... args) {
if (isNull()) {
reset(new T(std::forward<Args>(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;
};

View File

@ -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<AbstractStructure**>;
NeverFreedPointer<DataStructures> structures;
base::NeverFreedPointer<DataStructures> structures;
} // namespace

View File

@ -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<DocumentItems> documentItemsMap;
base::NeverFreedPointer<DocumentItems> documentItemsMap;
} // namespace

View File

@ -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<ImplementationsMap> Implementations;
base::NeverFreedPointer<ImplementationsMap> Implementations;
class TypingAnimation : public SendActionAnimation::Impl {
public:

View File

@ -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<void()> overrideKeep;
};
NeverFreedPointer<ChatBackground> GlobalBackground;
base::NeverFreedPointer<ChatBackground> GlobalBackground;
Applying GlobalApplying;
inline bool AreTestingTheme() {

@ -1 +1 @@
Subproject commit 117b8a248d4a74b90b7a3708622a53150f1fe88f
Subproject commit 1bc41f2cf875345c0965687fd8439f83aaa7738a