From cd7a71aba3de2c537a2f0f641c459c731dcecafd Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Tue, 3 Dec 2024 23:37:48 -0500 Subject: [PATCH] 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 --- include/crucible/hexdump.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/crucible/hexdump.h b/include/crucible/hexdump.h index 7e32591..2e099c2 100644 --- a/include/crucible/hexdump.h +++ b/include/crucible/hexdump.h @@ -12,12 +12,14 @@ namespace crucible { ostream & hexdump(ostream &os, const V &v) { - os << "V { size = " << v.size() << ", data:\n"; - for (size_t i = 0; i < v.size(); i += 8) { + const auto v_size = v.size(); + const uint8_t* const v_data = reinterpret_cast(v.data()); + os << "V { size = " << v_size << ", data:\n"; + for (size_t i = 0; i < v_size; i += 8) { string hex, ascii; for (size_t j = i; j < i + 8; ++j) { - if (j < v.size()) { - uint8_t c = v[j]; + if (j < v_size) { + const uint8_t c = v_data[j]; char buf[8]; sprintf(buf, "%02x ", c); hex += buf;