Browse Source

update: using stack char array

master
Dnomd343 2 years ago
parent
commit
8319d207d0
  1. 22
      src/core/core.cc
  2. 3
      src/short_code/serialize.cc

22
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) {

3
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

Loading…
Cancel
Save