mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 17:04:12 +08:00
after further testing, ThreadSafe<std::deque> seems to be the fastest and most reliable
This commit is contained in:
parent
94a8e2ce62
commit
e529046d7d
@ -23,7 +23,7 @@ void TextThread::Stop()
|
||||
|
||||
void TextThread::AddSentence(std::wstring&& sentence)
|
||||
{
|
||||
queuedSentences.push(std::move(sentence));
|
||||
queuedSentences->emplace_back(std::move(sentence));
|
||||
}
|
||||
|
||||
void TextThread::Push(BYTE* data, int length)
|
||||
@ -63,8 +63,9 @@ 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::wstring sentence;
|
||||
while (queuedSentences.try_pop(sentence))
|
||||
std::deque<std::wstring> sentences;
|
||||
queuedSentences->swap(sentences);
|
||||
for (auto& sentence : sentences)
|
||||
{
|
||||
sentence.erase(std::remove(sentence.begin(), sentence.end(), L'\0'));
|
||||
if (Output(*this, sentence)) storage->append(sentence);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include <concurrent_queue.h>
|
||||
#include <deque>
|
||||
|
||||
class TextThread
|
||||
{
|
||||
@ -37,7 +37,7 @@ private:
|
||||
std::unordered_set<wchar_t> repeatingChars;
|
||||
std::mutex bufferMutex;
|
||||
DWORD lastPushTime = 0;
|
||||
concurrency::concurrent_queue<std::wstring> queuedSentences;
|
||||
ThreadSafe<std::deque<std::wstring>> queuedSentences;
|
||||
struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
|
||||
AutoHandle<TimerDeleter> timer = NULL;
|
||||
};
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <Windows.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
Loading…
x
Reference in New Issue
Block a user