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)
|
void TextThread::AddSentence(std::wstring&& sentence)
|
||||||
{
|
{
|
||||||
queuedSentences.push(std::move(sentence));
|
queuedSentences->emplace_back(std::move(sentence));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextThread::Push(BYTE* data, int length)
|
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
|
if (storage->size() > 10'000'000) storage->erase(0, 8'000'000); // https://github.com/Artikash/Textractor/issues/127#issuecomment-486882983
|
||||||
|
|
||||||
std::wstring sentence;
|
std::deque<std::wstring> sentences;
|
||||||
while (queuedSentences.try_pop(sentence))
|
queuedSentences->swap(sentences);
|
||||||
|
for (auto& sentence : sentences)
|
||||||
{
|
{
|
||||||
sentence.erase(std::remove(sentence.begin(), sentence.end(), L'\0'));
|
sentence.erase(std::remove(sentence.begin(), sentence.end(), L'\0'));
|
||||||
if (Output(*this, sentence)) storage->append(sentence);
|
if (Output(*this, sentence)) storage->append(sentence);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <concurrent_queue.h>
|
#include <deque>
|
||||||
|
|
||||||
class TextThread
|
class TextThread
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ private:
|
|||||||
std::unordered_set<wchar_t> repeatingChars;
|
std::unordered_set<wchar_t> repeatingChars;
|
||||||
std::mutex bufferMutex;
|
std::mutex bufferMutex;
|
||||||
DWORD lastPushTime = 0;
|
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); } };
|
struct TimerDeleter { void operator()(HANDLE h) { DeleteTimerQueueTimer(NULL, h, INVALID_HANDLE_VALUE); } };
|
||||||
AutoHandle<TimerDeleter> timer = NULL;
|
AutoHandle<TimerDeleter> timer = NULL;
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
Loading…
Reference in New Issue
Block a user