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

Unified Diff: base/numerics/safe_conversions.h

Issue 2614073002: Cleanup RangeCheck class and dependencies (Closed)
Patch Set: remove integer saturation specialization Created 3 years, 11 months 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_conversions_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_conversions.h
diff --git a/base/numerics/safe_conversions.h b/base/numerics/safe_conversions.h
index e460039fc0894d33e8a228cc3ae9c2fe938fb1a9..b0ec279eb58551f9f792c18b43949951176083b3 100644
--- a/base/numerics/safe_conversions.h
+++ b/base/numerics/safe_conversions.h
@@ -106,39 +106,7 @@ struct SaturationDefaultHandler {
namespace internal {
-template <typename T, template <typename> class S>
-struct IsDefaultIntegralBounds {
- static const bool value =
- std::is_integral<T>::value &&
- S<T>::max() == SaturationDefaultHandler<T>::max() &&
- S<T>::lowest() == SaturationDefaultHandler<T>::lowest();
-};
-
-// Integral to integral conversions have a special optimization for the
-// standard bounds.
-template <typename Dst,
- template <typename> class S,
- typename Src,
- typename std::enable_if<
- std::is_integral<Src>::value &&
- IsDefaultIntegralBounds<Dst, S>::value>::type* = nullptr>
-constexpr Dst saturated_cast_impl(Src value, RangeCheck constraint) {
- using UnsignedDst = typename std::make_unsigned<Dst>::type;
- // The member fields in this class are lined up such that the compiler
- // can saturate without branching in this case by adding the register
- // with the bitfields directly to the integral max.
- return constraint.IsValid()
- ? static_cast<Dst>(value)
- : static_cast<Dst>(UnsignedDst(constraint.IsUnderflowFlagSet()) +
- std::numeric_limits<Dst>::max());
-}
-
-template <typename Dst,
- template <typename> class S,
- typename Src,
- typename std::enable_if<
- !std::is_integral<Src>::value ||
- !IsDefaultIntegralBounds<Dst, S>::value>::type* = nullptr>
+template <typename Dst, template <typename> class S, typename Src>
constexpr Dst saturated_cast_impl(Src value, RangeCheck constraint) {
// For some reason clang generates much better code when the branch is
// structured exactly this way, rather than a sequence of checks.
« no previous file with comments | « no previous file | base/numerics/safe_conversions_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698