From 678ed0ed00ee93b2f6989de7fb2bc10fb3fb2977 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 14 Nov 2024 23:50:30 +0100 Subject: Cleanup a bunch of lints --- .clang-tidy | 2 +- asl/format.cpp | 14 ++++++++------ asl/span.hpp | 14 +++++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9d00686..46025ae 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -29,4 +29,4 @@ Checks: - "-*-signed-bitwise" - "-readability-use-anyofallof" - "-readability-function-cognitive-complexity" -# - "-*-rvalue-reference-param-not-moved" + - "-readability-math-missing-parentheses" diff --git a/asl/format.cpp b/asl/format.cpp index f0b51e1..d25bade 100644 --- a/asl/format.cpp +++ b/asl/format.cpp @@ -118,7 +118,7 @@ void asl::AslFormat(formatter& f, uint32_t v) void asl::AslFormat(formatter& f, uint64_t v) { - static constexpr char pairs[] = { + static constexpr char s_pairs_storage[] = { '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', @@ -141,11 +141,13 @@ void asl::AslFormat(formatter& f, uint64_t v) '9', '5', '9', '6', '9', '7', '9', '8', '9', '9', }; + static constexpr span s_pairs = s_pairs_storage; + static constexpr int32_t kMaxDigits = 20; char buffer[kMaxDigits]; int32_t cursor = kMaxDigits; - auto write_two = [&buffer, &cursor](const char* str) + auto write_two = [&buffer, &cursor](span str) { ASL_ASSERT(cursor >= 2); buffer[--cursor] = str[1]; @@ -162,20 +164,20 @@ void asl::AslFormat(formatter& f, uint64_t v) { uint64_t x = v % 100; v /= 100; - write_two(pairs + x * 2); + write_two(s_pairs.subspan(static_cast(x * 2)).first<2>()); } if (v >= 10) { - write_two(pairs + v * 2); + write_two(s_pairs.subspan(static_cast(v * 2)).first<2>()); } else if (v > 0 || cursor == kMaxDigits) { ASL_ASSERT(v < 10); - write_one('0' + static_cast(v)); + write_one(static_cast('0' + v)); } - f.write({buffer + cursor, kMaxDigits - cursor}); + f.write(string_view(buffer, kMaxDigits).substr(cursor)); } void asl::AslFormat(formatter& f, int8_t v) diff --git a/asl/span.hpp b/asl/span.hpp index 7135509..8f6fb4a 100644 --- a/asl/span.hpp +++ b/asl/span.hpp @@ -125,15 +125,15 @@ public: } } - constexpr span subspan(isize_t offset, isize_t sub_size = dynamic_size) const + constexpr span subspan(isize_t offset) const { ASL_ASSERT(offset <= size()); - - if (is_dynamic(sub_size)) - { - return span{ data() + offset, size() - offset }; - } - + return span{ data() + offset, size() - offset }; + } + + constexpr span subspan(isize_t offset, isize_t sub_size) const + { + ASL_ASSERT(offset <= size() && !is_dynamic(sub_size)); ASL_ASSERT(sub_size <= size() - offset); return span{ data() + offset, sub_size }; } -- cgit