From 5e53e63e0706a8b3a3ba610092ca21dc0cab1834 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 6 Feb 2019 19:48:42 -0500 Subject: [PATCH] perf optimization --- GUI/host/textthread.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/GUI/host/textthread.cpp b/GUI/host/textthread.cpp index 62cbcfc..65bdce8 100644 --- a/GUI/host/textthread.cpp +++ b/GUI/host/textthread.cpp @@ -40,13 +40,16 @@ void TextThread::Push(const BYTE* data, int len) else if (auto converted = Util::StringToWideString(std::string((char*)data, len), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer += converted.value(); else Host::AddConsoleOutput(INVALID_CODEPAGE); lastPushTime = GetTickCount(); - - if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear(); - if (filterRepetition && Util::RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received + + if (filterRepetition) { - repeatingChars = std::unordered_set(buffer.begin(), buffer.end()); - AddSentence(buffer); - buffer.clear(); + if (std::all_of(buffer.begin(), buffer.end(), [&](auto ch) { return repeatingChars.find(ch) != repeatingChars.end(); })) buffer.clear(); + if (Util::RemoveRepetition(buffer)) // sentence repetition detected, which means the entire sentence has already been received + { + repeatingChars = std::unordered_set(buffer.begin(), buffer.end()); + AddSentence(buffer); + buffer.clear(); + } } }