From 8319d207d0e87639c2328334d52f3114587dc48f Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 16 Jan 2023 20:56:30 +0800 Subject: [PATCH] update: using stack char array --- src/core/core.cc | 22 +++++++++++----------- src/short_code/serialize.cc | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/core/core.cc b/src/core/core.cc index 1c54c1b..9b71b39 100644 --- a/src/core/core.cc +++ b/src/core/core.cc @@ -35,6 +35,17 @@ //////////////////////////////////////// +#define RELEASE(NEXT_CODE, FILTER) \ +cache_t next_case = { \ + .code = NEXT_CODE, \ + .mask = F_1x1 << next_addr, \ + .filter = FILTER, \ + .addr = next_addr \ +}; \ +cache_insert(next_case); + +//////////////////////////////////////// + #define BFS_INIT \ int next_addr; \ int current = 0; \ @@ -49,17 +60,6 @@ int filter = cache[current++].filter; //////////////////////////////////////// -#define RELEASE(NEXT_CODE, FILTER) \ -cache_t next_case = { \ - .code = NEXT_CODE, \ - .mask = F_1x1 << next_addr, \ - .filter = FILTER, \ - .addr = next_addr \ -}; \ -cache_insert(next_case); - -//////////////////////////////////////// - inline void Core::cache_insert(Core::cache_t &next_case) { // try to insert into cache auto *cache_ptr = cache; for (; cache_ptr < cache + cache_size; ++cache_ptr) { diff --git a/src/short_code/serialize.cc b/src/short_code/serialize.cc index f26c221..2e91991 100644 --- a/src/short_code/serialize.cc +++ b/src/short_code/serialize.cc @@ -8,7 +8,8 @@ ShortCode ShortCode::from_string(const std::string &short_code) { std::string ShortCode::to_string() const { // encode as 5-bits string uint32_t short_code = code; - std::string result(5, '\0'); // short code length 5 + char result[6]; // short code length 5 + result[5] = '\0'; // string ending flag for (int n = 0; n < 5; ++n) { result[4 - n] = SHORT_CODE_TABLE[short_code & 0b11111]; // aka _ % 32 short_code >>= 5; // aka _ / 32