From 28291942975710aafbe1ad6e879a581903a117b1 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 9 Jan 2023 23:55:27 +0800 Subject: [PATCH] perf: RawCode dump process --- src/raw_code/raw_code.cc | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/raw_code/raw_code.cc b/src/raw_code/raw_code.cc index b2adb69..8835ebf 100644 --- a/src/raw_code/raw_code.cc +++ b/src/raw_code/raw_code.cc @@ -70,41 +70,21 @@ RawCode::RawCode(const CommonCode &common_code) { } std::string RawCode::dump_case() const { - - // TODO: result reserve space -> result length std::string result; + result.reserve(40); // 5 lines * ("x x x x\n") + char dump_map[] = { + /// 0x0 1x2 2x1 1x1 2x2 b101 b110 fill + '.', '~', '|', '*', '@', '?', '?', '+' + }; auto raw_code = code; - for (int addr = 0; raw_code; ++addr, raw_code >>= 3) { - switch (raw_code & 0b111) { - case B_space: - result.push_back('.'); - break; - case B_fill: - result.push_back('+'); - break; - case B_1x1: - result.push_back('*'); - break; - case B_1x2: - result.push_back('~'); - break; - case B_2x1: - result.push_back('|'); - break; - case B_2x2: - result.push_back('@'); - break; - default: - result.push_back('?'); - } - if (addr % 4 == 3) { - result.push_back('\n'); + result.push_back(dump_map[raw_code & 0b111]); + if ((addr & 0b11) == 0b11) { + result.push_back('\n'); // new line } else { - result.push_back(' '); + result.push_back(' '); // add space } } - return result; }