From 678ed0ed00ee93b2f6989de7fb2bc10fb3fb2977 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic <steven.lerouzic@gmail.com> Date: Thu, 14 Nov 2024 23:50:30 +0100 Subject: Cleanup a bunch of lints --- asl/format.cpp | 14 ++++++++------ asl/span.hpp | 14 +++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'asl') 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<const char, 2> 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<isize_t>(x * 2)).first<2>()); } if (v >= 10) { - write_two(pairs + v * 2); + write_two(s_pairs.subspan(static_cast<isize_t>(v * 2)).first<2>()); } else if (v > 0 || cursor == kMaxDigits) { ASL_ASSERT(v < 10); - write_one('0' + static_cast<char>(v)); + write_one(static_cast<char>('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<T> subspan(isize_t offset, isize_t sub_size = dynamic_size) const + constexpr span<T> subspan(isize_t offset) const { ASL_ASSERT(offset <= size()); - - if (is_dynamic(sub_size)) - { - return span<T>{ data() + offset, size() - offset }; - } - + return span<T>{ data() + offset, size() - offset }; + } + + constexpr span<T> 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<T>{ data() + offset, sub_size }; } -- cgit