optimize dispatchsentence

This commit is contained in:
Akash Mozumdar 2019-01-01 17:50:22 -05:00
parent f080656e60
commit 3dd7be65ff
4 changed files with 7 additions and 8 deletions

View File

@ -54,28 +54,27 @@ namespace
}
}
bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std::string, int64_t> miscInfo)
bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<const char*, int64_t> miscInfo)
{
bool success = true;
wchar_t* sentenceBuffer = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentence.size() + 1) * sizeof(wchar_t));
wcscpy_s(sentenceBuffer, sentence.size() + 1, sentence.c_str());
InfoForExtension miscInfoLinkedList{ "", 0, nullptr };
InfoForExtension* miscInfoTraverser = &miscInfoLinkedList;
for (auto& i : miscInfo) miscInfoTraverser = miscInfoTraverser->next = new InfoForExtension{ i.first.c_str(), i.second, nullptr };
for (auto[name, value] : miscInfo) miscInfoTraverser = miscInfoTraverser->next = new InfoForExtension{ name, value, nullptr };
std::shared_lock sharedLock(extenMutex);
for (auto extenName : extenNames)
{
wchar_t* nextBuffer = extensions[extenName](sentenceBuffer, &miscInfoLinkedList);
if (nextBuffer == nullptr) { success = false; break; }
if (nextBuffer != sentenceBuffer) HeapFree(GetProcessHeap(), 0, sentenceBuffer);
if (nextBuffer == nullptr) return false;
sentenceBuffer = nextBuffer;
}
sentence = sentenceBuffer;
HeapFree(GetProcessHeap(), 0, sentenceBuffer);
return success;
return true;
}
ExtenWindow::ExtenWindow(QWidget* parent) :

View File

@ -7,7 +7,7 @@ namespace Ui
class ExtenWindow;
}
bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<std::string, int64_t> miscInfo);
bool DispatchSentenceToExtensions(std::wstring& sentence, std::unordered_map<const char*, int64_t> miscInfo);
class ExtenWindow : public QMainWindow
{

View File

@ -169,7 +169,7 @@ DWORD MainWindow::GetSelectedProcessId()
return ui->processCombo->currentText().split(":")[0].toULong(nullptr, 16);
}
std::unordered_map<std::string, int64_t> MainWindow::GetMiscInfo(TextThread* thread)
std::unordered_map<const char*, int64_t> MainWindow::GetMiscInfo(TextThread* thread)
{
return
{

View File

@ -24,7 +24,7 @@ private:
QString TextThreadString(TextThread* thread);
ThreadParam ParseTextThreadString(QString ttString);
DWORD GetSelectedProcessId();
std::unordered_map<std::string, int64_t> GetMiscInfo(TextThread* thread);
std::unordered_map<const char*, int64_t> GetMiscInfo(TextThread* thread);
void AttachProcess();
void DetachProcess();
void AddHook();