Chromium Code Reviews| Index: runtime/vm/object.h |
| =================================================================== |
| --- runtime/vm/object.h (revision 37592) |
| +++ runtime/vm/object.h (working copy) |
| @@ -5026,14 +5026,20 @@ |
| return reinterpret_cast<intptr_t>(New(value)); |
| } |
| - static bool IsValid(intptr_t value) { |
| - return (value >= kMinValue) && (value <= kMaxValue); |
| + template <typename T> |
| + static bool IsValid(T value) { |
| + COMPILE_ASSERT(sizeof(kMinValue) == sizeof(kMaxValue)); |
| + if (sizeof(value) < sizeof(kMinValue)) { |
|
Vyacheslav Egorov (Google)
2014/06/24 12:18:12
We also need to check that it is integral type bec
Florian Schneider
2014/06/24 12:35:06
Done. Added a COMPILE_ASSERT because we should nev
|
| + return true; |
| + } |
| + if (static_cast<T>(-1) < 0) { |
|
Vyacheslav Egorov (Google)
2014/06/24 12:18:12
I would really prefer we write C++ here:
std::num
Florian Schneider
2014/06/24 12:35:06
Done.
|
| + return (value >= static_cast<T>(kMinValue)) |
| + && (value <= static_cast<T>(kMaxValue)); |
| + } else { |
| + return value <= static_cast<T>(kMaxValue); |
| + } |
| } |
| - static bool IsValid64(int64_t value) { |
| - return (value >= kMinValue) && (value <= kMaxValue); |
| - } |
| - |
| RawInteger* ShiftOp(Token::Kind kind, |
| const Smi& other, |
| const bool silent = false) const; |