include/o3tl/safeint.hxx | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-)
New commits: commit 44a4b028d094dda4dc4886a4670371175da8024f Author: Mike Kaganski <[email protected]> AuthorDate: Wed Jul 28 03:30:35 2021 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Wed Jul 28 08:52:03 2021 +0200 Consolidate saturating_(add,sub) for signed and unsigned Compiler would optimize away the branch that is unreachable for current operand type anyway. Change-Id: Iac84057c1716990d107529d52dba1dd7603c5a32 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119448 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/include/o3tl/safeint.hxx b/include/o3tl/safeint.hxx index 801b3dc6fdd5..85c61f8c33d3 100644 --- a/include/o3tl/safeint.hxx +++ b/include/o3tl/safeint.hxx @@ -27,9 +27,7 @@ namespace o3tl { -template<typename T> inline -typename std::enable_if<std::is_signed<T>::value, T>::type saturating_add( - T a, T b) +template <typename T> inline T saturating_add(T a, T b) { if (b >= 0) { if (a <= std::numeric_limits<T>::max() - b) { @@ -46,20 +44,7 @@ typename std::enable_if<std::is_signed<T>::value, T>::type saturating_add( } } -template<typename T> inline -typename std::enable_if<std::is_unsigned<T>::value, T>::type saturating_add( - T a, T b) -{ - if (a <= std::numeric_limits<T>::max() - b) { - return a + b; - } else { - return std::numeric_limits<T>::max(); - } -} - -template<typename T> inline -typename std::enable_if<std::is_signed<T>::value, T>::type saturating_sub( - T a, T b) +template <typename T> inline T saturating_sub(T a, T b) { if (b >= 0) { if (a >= std::numeric_limits<T>::min() + b) { @@ -76,17 +61,6 @@ typename std::enable_if<std::is_signed<T>::value, T>::type saturating_sub( } } -template<typename T> inline -typename std::enable_if<std::is_unsigned<T>::value, T>::type saturating_sub( - T a, T b) -{ - if (a >= std::numeric_limits<T>::min() + b) { - return a - b; - } else { - return std::numeric_limits<T>::min(); - } -} - template<typename T> inline typename std::enable_if<std::is_signed<T>::value, T>::type saturating_toggle_sign( T a) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
