1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00

hexdump: be a little more lock-friendly

hexdump processes a vector as a contiguous sequence of bytes, regardless
of V's value type, so hexdump should get a pointer and use uint8_t to
read the data.

Some vector types have a lock and some atomics in their operator[], so
let's avoid hammering those.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2024-12-03 23:37:48 -05:00
parent e99a505b3b
commit cd7a71aba3

View File

@ -12,12 +12,14 @@ namespace crucible {
ostream & ostream &
hexdump(ostream &os, const V &v) hexdump(ostream &os, const V &v)
{ {
os << "V { size = " << v.size() << ", data:\n"; const auto v_size = v.size();
for (size_t i = 0; i < v.size(); i += 8) { const uint8_t* const v_data = reinterpret_cast<uint8_t*>(v.data());
os << "V { size = " << v_size << ", data:\n";
for (size_t i = 0; i < v_size; i += 8) {
string hex, ascii; string hex, ascii;
for (size_t j = i; j < i + 8; ++j) { for (size_t j = i; j < i + 8; ++j) {
if (j < v.size()) { if (j < v_size) {
uint8_t c = v[j]; const uint8_t c = v_data[j];
char buf[8]; char buf[8];
sprintf(buf, "%02x ", c); sprintf(buf, "%02x ", c);
hex += buf; hex += buf;