From dfa8184b5bce1a46e640bedb4c5cf694d22c98ce Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 16 Jan 2023 15:20:13 +0800 Subject: [PATCH] perf: using `std::stable_sort` instead of `std::sort` --- src/all_cases/basic_ranges.cc | 3 +-- src/main.cc | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/all_cases/basic_ranges.cc b/src/all_cases/basic_ranges.cc index ebf7b6a..064cf34 100644 --- a/src/all_cases/basic_ranges.cc +++ b/src/all_cases/basic_ranges.cc @@ -51,7 +51,7 @@ void BasicRanges::build_data() { // build basic ranges } } } - std::sort(BasicRanges::data.begin(), BasicRanges::data.end()); // sort basic ranges + std::stable_sort(BasicRanges::data.begin(), BasicRanges::data.end()); // sort basic ranges for (auto &range : BasicRanges::data) { range = Common::range_reverse(range); // basic ranges reverse } @@ -84,7 +84,6 @@ void BasicRanges::generate(generate_t info) { // generate specific basic ranges cache.pop(); continue; // skip search } - if (current.nx & 0xFF) { // n1 -> `00` cache.emplace(build_t { .nx = current.nx - 0x01, // --n1 diff --git a/src/main.cc b/src/main.cc index 186aec6..9196f97 100644 --- a/src/main.cc +++ b/src/main.cc @@ -245,7 +245,7 @@ int main() { // } -// BasicRanges::build(); + BasicRanges::build(); // const auto &br = BasicRanges::fetch(); // br.push_back(123); // std::cout << "size: " << BasicRanges::fetch().size() << std::endl; @@ -270,7 +270,7 @@ int main() { // } // printf("%09lX\n", ShortCode::tiny_decode_demo(14323231)); - std::cout << ShortCode::tiny_encode_demo(0x6EC0F8800) << std::endl; +// std::cout << ShortCode::tiny_encode_demo(0x6EC0F8800) << std::endl; // auto br = BasicRanges::fetch(); // for (auto &range : br) {