From 9539b5430f6265b34f0b8e8bc5c90d1ef708caa6 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 28 May 2021 02:41:41 +0200 Subject: [PATCH] Some small code improvements --- include/duckhandy/bitfield_pack.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/duckhandy/bitfield_pack.hpp b/include/duckhandy/bitfield_pack.hpp index a837587..bccc161 100644 --- a/include/duckhandy/bitfield_pack.hpp +++ b/include/duckhandy/bitfield_pack.hpp @@ -99,7 +99,8 @@ namespace dhandy { }; template - constexpr inline T make_mask (std::size_t len) { + [[gnu::const]] + constexpr inline T make_mask (std::size_t len) noexcept { return (1 << len) - 1; } } //namespace implem @@ -118,7 +119,7 @@ namespace dhandy { template friend U get (const BitfieldPack&); template friend void set (BitfieldPack&, V); typedef implem::BitfieldData base_type; - static_assert(Facts::LargestSize <= sizeof(T) * CHAR_BIT, "Bitfield size can't be larget than the data type itself"); + static_assert(Facts::LargestSize <= sizeof(T) * CHAR_BIT, "Bitfield size can't be larger than the data type itself"); public: BitfieldPack (T init=T{}) : base_type(init) {} }; @@ -136,14 +137,15 @@ namespace dhandy { const constexpr bool bleeds_into_next = reloffs + so.size > sizeof(T) * CHAR_BIT; const T bottom = static_cast&>(pack).value() >> reloffs; - if (bleeds_into_next) { - const std::size_t safe_index = index + 2 - not bleeds_into_next; + if constexpr (bleeds_into_next) { + const std::size_t safe_index = index + 2; const T val = static_cast&>(pack).value(); const T top = val << (sizeof(T) * CHAR_BIT - reloffs); return static_cast(top | bottom) & make_mask(so.size); } - - return bottom & make_mask(so.size); + else { + return bottom & make_mask(so.size); + } } template