| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 public: | 105 public: |
| 106 bool hasOverflowed() const { return m_overflowed; } | 106 bool hasOverflowed() const { return m_overflowed; } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 unsigned char m_overflowed; | 109 unsigned char m_overflowed; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 template <typename T, class OverflowHandler = CrashOnOverflow> class Checked; | 112 template <typename T, class OverflowHandler = CrashOnOverflow> class Checked; |
| 113 template <typename T> struct RemoveChecked; | 113 template <typename T> struct RemoveChecked; |
| 114 template <typename T> struct RemoveChecked<Checked<T> >; | 114 template <typename T> struct RemoveChecked<Checked<T>>; |
| 115 | 115 |
| 116 template <typename Target, typename Source, bool targetSigned = std::numeric_lim
its<Target>::is_signed, bool sourceSigned = std::numeric_limits<Source>::is_sign
ed> struct BoundsChecker; | 116 template <typename Target, typename Source, bool targetSigned = std::numeric_lim
its<Target>::is_signed, bool sourceSigned = std::numeric_limits<Source>::is_sign
ed> struct BoundsChecker; |
| 117 template <typename Target, typename Source> struct BoundsChecker<Target, Source,
false, false> { | 117 template <typename Target, typename Source> struct BoundsChecker<Target, Source,
false, false> { |
| 118 static bool inBounds(Source value) | 118 static bool inBounds(Source value) |
| 119 { | 119 { |
| 120 // Same signedness so implicit type conversion will always increase prec
ision | 120 // Same signedness so implicit type conversion will always increase prec
ision |
| 121 // to widest type | 121 // to widest type |
| 122 return value <= std::numeric_limits<Target>::max(); | 122 return value <= std::numeric_limits<Target>::max(); |
| 123 } | 123 } |
| 124 }; | 124 }; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 template <typename Target, typename Source> static inline bool isInBounds(Source
value) | 170 template <typename Target, typename Source> static inline bool isInBounds(Source
value) |
| 171 { | 171 { |
| 172 return BoundsCheckElider<Target, Source>::inBounds(value); | 172 return BoundsCheckElider<Target, Source>::inBounds(value); |
| 173 } | 173 } |
| 174 | 174 |
| 175 template <typename T> struct RemoveChecked { | 175 template <typename T> struct RemoveChecked { |
| 176 typedef T CleanType; | 176 typedef T CleanType; |
| 177 static const CleanType DefaultValue = 0; | 177 static const CleanType DefaultValue = 0; |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 template <typename T> struct RemoveChecked<Checked<T, CrashOnOverflow> > { | 180 template <typename T> struct RemoveChecked<Checked<T, CrashOnOverflow>> { |
| 181 typedef typename RemoveChecked<T>::CleanType CleanType; | 181 typedef typename RemoveChecked<T>::CleanType CleanType; |
| 182 static const CleanType DefaultValue = 0; | 182 static const CleanType DefaultValue = 0; |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 template <typename T> struct RemoveChecked<Checked<T, RecordOverflow> > { | 185 template <typename T> struct RemoveChecked<Checked<T, RecordOverflow>> { |
| 186 typedef typename RemoveChecked<T>::CleanType CleanType; | 186 typedef typename RemoveChecked<T>::CleanType CleanType; |
| 187 static const CleanType DefaultValue = 0; | 187 static const CleanType DefaultValue = 0; |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 // The ResultBase and SignednessSelector are used to workaround typeof not being | 190 // The ResultBase and SignednessSelector are used to workaround typeof not being |
| 191 // available in MSVC | 191 // available in MSVC |
| 192 template <typename U, typename V, bool uIsBigger = (sizeof(U) > sizeof(V)), bool
sameSize = (sizeof(U) == sizeof(V))> struct ResultBase; | 192 template <typename U, typename V, bool uIsBigger = (sizeof(U) > sizeof(V)), bool
sameSize = (sizeof(U) == sizeof(V))> struct ResultBase; |
| 193 template <typename U, typename V> struct ResultBase<U, V, true, false> { | 193 template <typename U, typename V> struct ResultBase<U, V, true, false> { |
| 194 typedef U ResultType; | 194 typedef U ResultType; |
| 195 }; | 195 }; |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 return Checked<U, OverflowHandler>(lhs) * rhs; | 706 return Checked<U, OverflowHandler>(lhs) * rhs; |
| 707 } | 707 } |
| 708 | 708 |
| 709 } | 709 } |
| 710 | 710 |
| 711 using WTF::Checked; | 711 using WTF::Checked; |
| 712 using WTF::CheckedState; | 712 using WTF::CheckedState; |
| 713 using WTF::RecordOverflow; | 713 using WTF::RecordOverflow; |
| 714 | 714 |
| 715 #endif | 715 #endif |
| OLD | NEW |