diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-05-20 12:22:27 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-05-20 12:22:27 +0100 |
| commit | 161f32ebaea5988fe97ad03ad669eca2222e2a54 (patch) | |
| tree | 1e45b2cd3f9b35238e6cc2a86334bbc5d02235f8 | |
| parent | a3d868ca57591a6d977da8a7e9ec5c14976e73ec (diff) | |
| download | webstat-161f32ebaea5988fe97ad03ad669eca2222e2a54.tar.bz2 webstat-161f32ebaea5988fe97ad03ad669eca2222e2a54.tar.xz webstat-161f32ebaea5988fe97ad03ad669eca2222e2a54.zip | |
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.
| -rw-r--r-- | src/ingestor.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
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<const uint8_t>; - - 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) { |
