after further testing, ThreadSafe<std::deque> seems to be the fastest and most reliable

This commit is contained in:
Akash Mozumdar 2019-06-04 15:21:04 -04:00
parent 94a8e2ce62
commit e529046d7d
3 changed files with 7 additions and 5 deletions

View File

@ -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);

View File

@ -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;
};

View File

@ -4,6 +4,7 @@
#include <Windows.h>
#include <string>
#include <vector>
#include <deque>
#include <array>
#include <unordered_map>
#include <unordered_set>