From 920a2d6d029c1ff96959d39efae8600a4d39e975 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 14 Dec 2024 12:51:42 +0800 Subject: [PATCH] update: move serialize logic into `.inl` file --- src/core/CMakeLists.txt | 2 +- src/core/benchmark/common_code.cc | 12 ++++++------ src/core/common_code/common_code.h | 1 + .../internal/{serialize.cc => serialize.inl} | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) rename src/core/common_code/internal/{serialize.cc => serialize.inl} (91%) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3790ce2..b95cbb5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -11,7 +11,7 @@ set(KLSK_CORE_SRC all_cases/internal/all_cases.cc # common_code/internal/common_code.cc - common_code/internal/serialize.cc +# common_code/internal/serialize.cc # common_code/internal/mirror.cc # raw_code/internal/raw_code.cc diff --git a/src/core/benchmark/common_code.cc b/src/core/benchmark/common_code.cc index ae7b623..d83140d 100644 --- a/src/core/benchmark/common_code.cc +++ b/src/core/benchmark/common_code.cc @@ -138,14 +138,14 @@ static void CommonCodeHorizontalMirror(benchmark::State &state) { // BENCHMARK(CommonCodeCheck)->Range(8, 256); -// BENCHMARK(CommonCodeSerialize)->Range(8, 256); -// BENCHMARK(CommonCodeDeserialize)->Range(8, 256); -// BENCHMARK(CommonCodeSerializeShorten)->Range(8, 256); -// BENCHMARK(CommonCodeDeserializeShorten)->Range(8, 256); +BENCHMARK(CommonCodeSerialize)->Range(16, 1024); +BENCHMARK(CommonCodeDeserialize)->Range(16, 1024); +BENCHMARK(CommonCodeSerializeShorten)->Range(16, 1024); +BENCHMARK(CommonCodeDeserializeShorten)->Range(16, 1024); // BENCHMARK(CommonCodeCheckMirror)->Range(64, 1024); -BENCHMARK(CommonCodeVerticalMirror)->Range(8, 256); -BENCHMARK(CommonCodeHorizontalMirror)->Range(8, 256); +// BENCHMARK(CommonCodeVerticalMirror)->Range(8, 256); +// BENCHMARK(CommonCodeHorizontalMirror)->Range(8, 256); BENCHMARK_MAIN(); diff --git a/src/core/common_code/common_code.h b/src/core/common_code/common_code.h index 9f5c083..213833a 100644 --- a/src/core/common_code/common_code.h +++ b/src/core/common_code/common_code.h @@ -199,6 +199,7 @@ static_assert(std::is_trivially_copyable_v); } // namespace klotski::codec #include "internal/common_code.inl" +#include "internal/serialize.inl" #include "internal/mirror.inl" #include "internal/check.inl" diff --git a/src/core/common_code/internal/serialize.cc b/src/core/common_code/internal/serialize.inl similarity index 91% rename from src/core/common_code/internal/serialize.cc rename to src/core/common_code/internal/serialize.inl index 63315b1..65ad95b 100644 --- a/src/core/common_code/internal/serialize.cc +++ b/src/core/common_code/internal/serialize.inl @@ -1,4 +1,4 @@ -#include "common_code/common_code.h" +#pragma once namespace klotski::codec { @@ -53,7 +53,7 @@ constexpr auto CONVERT_TABLE = std::to_array({ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }); -std::string CommonCode::string_encode(uint64_t common_code) { +inline std::string CommonCode::string_encode(uint64_t common_code) { char code_str[9]; for (int i = 0; i < 9; ++i) { code_str[8 - i] = to_hex_char(common_code & 0b1111); @@ -62,7 +62,7 @@ std::string CommonCode::string_encode(uint64_t common_code) { return std::string{code_str, code_str + 9}; } -std::string CommonCode::string_encode_shorten(const uint64_t common_code) { +inline std::string CommonCode::string_encode_shorten(const uint64_t common_code) { if (common_code == 0) { return "0"; // special case } @@ -71,7 +71,7 @@ std::string CommonCode::string_encode_shorten(const uint64_t common_code) { return code; } -std::optional CommonCode::string_decode(const std::string_view common_code) { +inline std::optional CommonCode::string_decode(const std::string_view common_code) { if (common_code.length() > 9 || common_code.empty()) { return std::nullopt; // invalid string length }