performance improvement. or maybe not idk my benchmarks make no sense but i think it's better
This commit is contained in:
parent
02f127e80c
commit
494fcd24c3
@ -23,7 +23,7 @@ void TextThread::Stop()
|
||||
|
||||
void TextThread::AddSentence(std::wstring&& sentence)
|
||||
{
|
||||
queuedSentences->emplace_back(std::move(sentence));
|
||||
queuedSentences.push(std::move(sentence));
|
||||
}
|
||||
|
||||
void TextThread::Push(BYTE* data, int length)
|
||||
@ -51,15 +51,20 @@ void TextThread::Push(BYTE* data, int length)
|
||||
buffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (flushDelay == 0 && hp.type & USING_STRING)
|
||||
{
|
||||
AddSentence(std::move(buffer));
|
||||
buffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void TextThread::Flush()
|
||||
{
|
||||
if (storage->size() > 10'000'000) storage->erase(0, 8'000'000); // https://github.com/Artikash/Textractor/issues/127#issuecomment-486882983
|
||||
|
||||
std::vector<std::wstring> sentences;
|
||||
queuedSentences->swap(sentences);
|
||||
for (auto& sentence : sentences)
|
||||
std::wstring sentence;
|
||||
while (queuedSentences.try_pop(sentence))
|
||||
{
|
||||
sentence.erase(std::remove(sentence.begin(), sentence.end(), L'\0'));
|
||||
if (Output(*this, sentence)) storage->append(sentence);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include <concurrent_queue.h>
|
||||
|
||||
class TextThread
|
||||
{
|
||||
@ -36,7 +37,7 @@ private:
|
||||
std::unordered_set<wchar_t> repeatingChars;
|
||||
std::mutex bufferMutex;
|
||||
DWORD lastPushTime = 0;
|
||||
ThreadSafe<std::vector<std::wstring>> queuedSentences;
|
||||
concurrency::concurrent_queue<std::wstring> queuedSentences;
|
||||
struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
|
||||
AutoHandle<TimerDeleter> timer = NULL;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user