Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2629)

Unified Diff: base/numerics/safe_conversions_impl.h

Issue 2600853004: Minor base/numerics cleanup (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/numerics/safe_math_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_conversions_impl.h
diff --git a/base/numerics/safe_conversions_impl.h b/base/numerics/safe_conversions_impl.h
index 75676e199384cb1abe2c73d1c2548a3b4d68a5e2..df7130d7c2df9f6b7052fd012c8b280545545778 100644
--- a/base/numerics/safe_conversions_impl.h
+++ b/base/numerics/safe_conversions_impl.h
@@ -37,19 +37,6 @@ struct PositionOfSignBit {
static const size_t value = IntegerBitsPlusSign<Integer>::value - 1;
};
-template <typename T>
-constexpr bool HasSignBit(T x) {
- // Cast to unsigned since right shift on signed is undefined.
- return (static_cast<typename std::make_unsigned<T>::type>(x) >>
- PositionOfSignBit<T>::value) != 0;
-}
-
-// This wrapper undoes the standard integer promotions.
-template <typename T>
-constexpr T BinaryComplement(T x) {
- return static_cast<T>(~x);
-}
-
// Determines if a numeric value is negative without throwing compiler
// warnings on: unsigned(value) < 0.
template <typename T,
@@ -91,7 +78,7 @@ constexpr T SignMask(T x) {
(static_cast<SignedT>(-1) >> PositionOfSignBit<T>::value) ==
static_cast<SignedT>(-1)
? (static_cast<SignedT>(x) >> PositionOfSignBit<T>::value)
- : -static_cast<SignedT>(HasSignBit(x)));
+ : -static_cast<SignedT>(static_cast<SignedT>(x) < 0));
}
static_assert(SignMask(-2) == -1,
"Inconsistent handling of signed right shift.");
« no previous file with comments | « no previous file | base/numerics/safe_math_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698