mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-16 04:02:09 +00:00
NeverFreedPointer implementation improved and fixed for MSVC.
This commit is contained in:
parent
a37bbcfaca
commit
a56ece4efe
@ -824,6 +824,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void makeIfNull(Args&&... args) {
|
||||
if (isNull()) {
|
||||
reset(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
};
|
||||
|
||||
T *data() const {
|
||||
return _p;
|
||||
}
|
||||
@ -857,13 +864,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using NeverFreedPointerCreator = T*(*)();
|
||||
template <typename T, typename... Args>
|
||||
inline NeverFreedPointerCreator<T> MakeNeverFreedCreator(Args&&... args) {
|
||||
return [&args...]() -> T* { return new T(std_::forward<Args>(args)...); };
|
||||
}
|
||||
|
||||
// This pointer is used for static non-POD variables that are allocated
|
||||
// on first use by constructor and are never automatically freed.
|
||||
template <typename T>
|
||||
|
@ -86,7 +86,7 @@ bool ClickHandler::setActive(const ClickHandlerPtr &p, ClickHandlerHost *host) {
|
||||
}
|
||||
}
|
||||
if (p) {
|
||||
_active.createIfNull(MakeNeverFreedCreator<ClickHandlerPtr>());
|
||||
_active.makeIfNull();
|
||||
*_active = p;
|
||||
if ((_activeHost = host)) {
|
||||
bool emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active);
|
||||
|
@ -366,7 +366,7 @@ public:
|
||||
if (!_active || !*_active) {
|
||||
return;
|
||||
}
|
||||
_pressed.createIfNull(MakeNeverFreedCreator<ClickHandlerPtr>());
|
||||
_pressed.makeIfNull();
|
||||
*_pressed = *_active;
|
||||
if ((_pressedHost = _activeHost)) {
|
||||
_pressedHost->clickHandlerPressedChanged(*_pressed, true);
|
||||
|
Loading…
Reference in New Issue
Block a user