diff options
author | David Robillard <d@drobilla.net> | 2018-08-26 20:58:15 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-29 14:50:31 +0200 |
commit | 935807ad1a4214be21c65acc80a715e010dc7a92 (patch) | |
tree | 06f27c1eb0c04466dc0d4d02733136558e6ecfbf | |
parent | 845ff6488070a91dd8c021608fc391b5a79d01b2 (diff) | |
download | chilbert-935807ad1a4214be21c65acc80a715e010dc7a92.tar.gz chilbert-935807ad1a4214be21c65acc80a715e010dc7a92.tar.bz2 chilbert-935807ad1a4214be21c65acc80a715e010dc7a92.zip |
Explicitly factor out some const expressions
-rw-r--r-- | chilbert/detail/MultiBitVec.hpp | 10 | ||||
-rw-r--r-- | chilbert/detail/operations.hpp | 3 |
2 files changed, 8 insertions, 5 deletions
diff --git a/chilbert/detail/MultiBitVec.hpp b/chilbert/detail/MultiBitVec.hpp index 4bf5085..283601f 100644 --- a/chilbert/detail/MultiBitVec.hpp +++ b/chilbert/detail/MultiBitVec.hpp @@ -351,11 +351,13 @@ gray_code(MultiBitVec<Derived>& value) { typename MultiBitVec<Derived>::Rack s = 0; + constexpr size_t left_shift = MultiBitVec<Derived>::bits_per_rack - 1; for (size_t ri = 0; ri < value.num_racks(); ++ri) { - const size_t i = value.num_racks() - ri - 1; - const auto t = value.rack(i) & 1; - gray_code(value.rack(i)); - value.rack(i) ^= (s << (MultiBitVec<Derived>::bits_per_rack - 1)); + const size_t i = value.num_racks() - ri - 1; + auto& rack = value.rack(i); + const auto t = rack & 1; + gray_code(rack); + rack ^= (s << left_shift); s = t; } } diff --git a/chilbert/detail/operations.hpp b/chilbert/detail/operations.hpp index 94635b4..1c6b8bf 100644 --- a/chilbert/detail/operations.hpp +++ b/chilbert/detail/operations.hpp @@ -157,7 +157,8 @@ template <typename T> std::enable_if_t<std::is_integral<T>::value> gray_code_inv(T& value) { - for (T shift = 1; shift < sizeof(T) * CHAR_BIT; shift <<= 1) { + constexpr T shift_end = sizeof(T) * CHAR_BIT; + for (T shift = 1; shift < shift_end; shift <<= 1) { value ^= (value >> shift); } } |