mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-29 02:33:30 +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 {
|
T *data() const {
|
||||||
return _p;
|
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
|
// This pointer is used for static non-POD variables that are allocated
|
||||||
// on first use by constructor and are never automatically freed.
|
// on first use by constructor and are never automatically freed.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -86,7 +86,7 @@ bool ClickHandler::setActive(const ClickHandlerPtr &p, ClickHandlerHost *host) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p) {
|
if (p) {
|
||||||
_active.createIfNull(MakeNeverFreedCreator<ClickHandlerPtr>());
|
_active.makeIfNull();
|
||||||
*_active = p;
|
*_active = p;
|
||||||
if ((_activeHost = host)) {
|
if ((_activeHost = host)) {
|
||||||
bool emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active);
|
bool emitClickHandlerActiveChanged = (!_pressed || !*_pressed || *_pressed == *_active);
|
||||||
|
@ -366,7 +366,7 @@ public:
|
|||||||
if (!_active || !*_active) {
|
if (!_active || !*_active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_pressed.createIfNull(MakeNeverFreedCreator<ClickHandlerPtr>());
|
_pressed.makeIfNull();
|
||||||
*_pressed = *_active;
|
*_pressed = *_active;
|
||||||
if ((_pressedHost = _activeHost)) {
|
if ((_pressedHost = _activeHost)) {
|
||||||
_pressedHost->clickHandlerPressedChanged(*_pressed, true);
|
_pressedHost->clickHandlerPressedChanged(*_pressed, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user