From 161f32ebaea5988fe97ad03ad669eca2222e2a54 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 20 May 2026 12:22:27 +0100 Subject: Change bytesToHexRange into a transform view variable Simply create the transform constexpr and then apply it to any collection with the restriction of passing it to a function. --- src/ingestor.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ingestor.cpp b/src/ingestor.cpp index 954f872..200397b 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -26,19 +26,13 @@ namespace DB { namespace WebStat { namespace { - using ByteArrayView = std::span; - - auto - bytesToHexRange(const ByteArrayView bytes) - { + constexpr auto TO_HEX_RANGE = std::views::transform([](auto byte) { constexpr auto HEXN = 16ZU; - return bytes | std::views::transform([](auto byte) { - return std::array {byte / HEXN, byte % HEXN}; - }) | std::views::join - | std::views::transform([](auto nibble) { - return "0123456789abcdef"[nibble]; - }); - } + return std::array {byte / HEXN, byte % HEXN}; + }) | std::views::join + | std::views::transform([](auto nibble) { + return "0123456789abcdef"[nibble]; + }); EntityHash makeHash(const std::string_view value) @@ -458,7 +452,7 @@ namespace WebStat { return std::unexpected(0); } const std::filesystem::path path { - settings.fallbackDir / std::format("parked-{:s}.short", bytesToHexRange(makeHash(lines.front())))}; + settings.fallbackDir / std::format("parked-{:s}.short", makeHash(lines.front()) | TO_HEX_RANGE)}; if (auto parked = FilePtr(fopen(path.c_str(), "w"))) { fprintf(parked.get(), "%zu\n", lines.size()); for (const auto & line : lines) { -- cgit v1.3