PITimer slot optimize
This commit is contained in:
@@ -122,13 +122,13 @@ PITimer::PITimer(): PIObject() {
|
||||
|
||||
PITimer::PITimer(std::function<void(int)> func) {
|
||||
initFirst();
|
||||
ret_func = func;
|
||||
ret_func_delim = std::move(func);
|
||||
}
|
||||
|
||||
|
||||
PITimer::PITimer(std::function<void()> func) {
|
||||
initFirst();
|
||||
ret_func = [func](int) { func(); };
|
||||
ret_func = std::move(func);
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,8 @@ void PITimer::adjustTimes() {
|
||||
void PITimer::execTick() {
|
||||
if (!isRunning()) return;
|
||||
if (lockRun) lock();
|
||||
if (ret_func) ret_func(1);
|
||||
if (ret_func) ret_func();
|
||||
if (ret_func_delim) ret_func_delim(1);
|
||||
tick(1);
|
||||
tickEvent(1);
|
||||
if (callEvents) maybeCallQueuedEvents();
|
||||
@@ -233,8 +234,8 @@ void PITimer::execTick() {
|
||||
i.tick = 0;
|
||||
if (i.func)
|
||||
i.func(i.delim);
|
||||
else if (ret_func)
|
||||
ret_func(i.delim);
|
||||
else if (ret_func_delim)
|
||||
ret_func_delim(i.delim);
|
||||
tick(i.delim);
|
||||
tickEvent(i.delim);
|
||||
}
|
||||
|
||||
@@ -126,13 +126,11 @@ public:
|
||||
|
||||
//! \~english Sets a tick callback that ignores the delimiter value.
|
||||
//! \~russian Устанавливает обратный вызов тика, игнорирующий значение делителя.
|
||||
void setSlot(std::function<void()> func) {
|
||||
ret_func = [func](int) { func(); };
|
||||
}
|
||||
void setSlot(std::function<void()> func) { ret_func = std::move(func); }
|
||||
|
||||
//! \~english Sets a tick callback that receives the current delimiter value.
|
||||
//! \~russian Устанавливает обратный вызов тика, принимающий текущее значение делителя.
|
||||
void setSlot(std::function<void(int)> func) { ret_func = func; }
|
||||
void setSlot(std::function<void(int)> func) { ret_func_delim = std::move(func); }
|
||||
|
||||
//! \~english Enables locking of the internal mutex around tick processing.
|
||||
//! \~russian Включает блокировку внутреннего мьютекса вокруг обработки тиков.
|
||||
@@ -245,7 +243,8 @@ protected:
|
||||
PIMutex mutex_;
|
||||
PISystemTime m_interval, m_interval_x5;
|
||||
PISystemTime m_time_next;
|
||||
std::function<void(int)> ret_func = nullptr;
|
||||
std::function<void()> ret_func = nullptr;
|
||||
std::function<void(int)> ret_func_delim = nullptr;
|
||||
PIVector<Delimiter> delims;
|
||||
PIConditionVariable event;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user