From 8f03dc024ff6db79a6a8c0a43fbc085e4d8e7aa4 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 13 Jan 2023 13:54:36 +0800 Subject: [PATCH] feat: try to reduce repeated hash searches --- src/analyse/analyse.cc | 74 ++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/src/analyse/analyse.cc b/src/analyse/analyse.cc index 801986a..66e7f84 100644 --- a/src/analyse/analyse.cc +++ b/src/analyse/analyse.cc @@ -11,27 +11,8 @@ Core Analyse::new_core() { ); } -class test_c { -public: - test_c() { - std::cout << "class init" << std::endl; - } -}; - -struct test_t { - uint64_t data; - test_c demo; -}; - void Analyse::start_analyse(uint64_t code) { - auto t = test_t { - .data = 123, -// data: 123, - }; - - return; - auto core = new_core(); cases.empty(); @@ -43,14 +24,9 @@ void Analyse::start_analyse(uint64_t code) { .code = code, .mask = 0, .step = 0, -// .src = std::move(std::vector{}), - .src = std::move(std::list{}), -// .src = std::move(std::set{}), -// .src = std::move(std::unordered_set{}), +// .src = std::move(std::list{}), }).first->second); -// std::cout << "src size: " << cases[code].src.size() << std::endl; - while (!cache.empty()) { core.next_step(cache.front()->code, cache.front()->mask); @@ -62,27 +38,41 @@ void Analyse::start_analyse(uint64_t code) { } void Analyse::new_case(uint64_t code, uint64_t mask) { - auto current = cases.find(code); - if (current != cases.end()) { // find existed case - current->second.mask |= mask; // update mask info -// current->second.src.emplace() - if (current->second.step != cache.front()->step) { -// current->second.src.emplace(cache.front()); - current->second.src.push_back(cache.front()); + auto temp = cases.emplace(code, analyse_t { + .code = code, + .mask = mask, + .step = cache.front()->step + 1, + .src = std::move(std::list{cache.front()}) + }); + + if (temp.second) { + cache.emplace(&temp.first->second); + } else { + temp.first->second.mask |= mask; + + if (temp.first->second.step != cache.front()->step) { + temp.first->second.src.push_back(cache.front()); } - return; } - cache.emplace(&cases.emplace(code, analyse_t { - .code = code, - .mask = mask, - .step = cache.front()->step + 1, -// .src = std::move(std::vector{cache.front()}), - .src = std::move(std::list{cache.front()}), -// .src = std::move(std::set{cache.front()}), -// .src = std::move(std::unordered_set{cache.front()}), - }).first->second); +// auto current = cases.find(code); +// if (current != cases.end()) { // find existed case +// current->second.mask |= mask; // update mask info +// +// if (current->second.step != cache.front()->step) { +// current->second.src.push_back(cache.front()); +// } +// +// return; +// } +// +// cache.emplace(&cases.emplace(code, analyse_t { +// .code = code, +// .mask = mask, +// .step = cache.front()->step + 1, +// .src = std::move(std::list{cache.front()}), +// }).first->second); }