refactor
This commit is contained in:
parent
a3ac850bf4
commit
dfb45a3699
@ -10,7 +10,7 @@ TextThread::TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring>
|
|||||||
tp(tp),
|
tp(tp),
|
||||||
hp(hp)
|
hp(hp)
|
||||||
{
|
{
|
||||||
CreateTimerQueueTimer(timer, NULL, Flush, this, 25, 25, WT_EXECUTELONGFUNCTION);
|
CreateTimerQueueTimer(timer, NULL, [](void* This, BOOLEAN) { ((TextThread*)This)->Flush(); }, this, 25, 25, WT_EXECUTELONGFUNCTION);
|
||||||
OnCreate(this);
|
OnCreate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,19 +40,18 @@ void TextThread::Push(const BYTE* data, int len)
|
|||||||
lastPushTime = GetTickCount();
|
lastPushTime = GetTickCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CALLBACK Flush(void* thread, BOOLEAN)
|
void TextThread::Flush()
|
||||||
{
|
{
|
||||||
auto This = (TextThread*)thread;
|
|
||||||
std::wstring sentence;
|
std::wstring sentence;
|
||||||
{
|
{
|
||||||
LOCK(This->bufferMutex);
|
LOCK(bufferMutex);
|
||||||
if (This->buffer.empty()) return;
|
if (buffer.empty()) return;
|
||||||
if (This->buffer.size() < This->maxBufferSize && GetTickCount() - This->lastPushTime < This->flushDelay) return;
|
if (buffer.size() < maxBufferSize && GetTickCount() - lastPushTime < flushDelay) return;
|
||||||
sentence = This->buffer;
|
sentence = buffer;
|
||||||
This->buffer.clear();
|
buffer.clear();
|
||||||
|
|
||||||
if (Util::RemoveRepetition(sentence)) This->repeatingChars = std::unordered_set(sentence.begin(), sentence.end());
|
if (Util::RemoveRepetition(sentence)) repeatingChars = std::unordered_set(sentence.begin(), sentence.end());
|
||||||
else This->repeatingChars.clear();
|
else repeatingChars.clear();
|
||||||
}
|
}
|
||||||
This->AddSentence(sentence);
|
AddSentence(sentence);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ public:
|
|||||||
std::wstring GetStorage();
|
std::wstring GetStorage();
|
||||||
void AddSentence(std::wstring sentence);
|
void AddSentence(std::wstring sentence);
|
||||||
void Push(const BYTE* data, int len);
|
void Push(const BYTE* data, int len);
|
||||||
friend void CALLBACK Flush(void* thread, BOOLEAN);
|
|
||||||
|
|
||||||
const int64_t handle;
|
const int64_t handle;
|
||||||
const std::wstring name;
|
const std::wstring name;
|
||||||
@ -30,8 +29,9 @@ public:
|
|||||||
const HookParam hp;
|
const HookParam hp;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct TimerDeleter { void operator()(void* h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
|
void Flush();
|
||||||
|
|
||||||
|
struct TimerDeleter { void operator()(void* h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
|
||||||
ThreadSafePtr<std::wstring> storage;
|
ThreadSafePtr<std::wstring> storage;
|
||||||
std::wstring buffer;
|
std::wstring buffer;
|
||||||
std::unordered_set<wchar_t> repeatingChars;
|
std::unordered_set<wchar_t> repeatingChars;
|
||||||
|
Loading…
Reference in New Issue
Block a user