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

Unified Diff: runtime/vm/object.h

Issue 353513002: Use range information for optimizing integer boxing and fix bug in range analysis. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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
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;

Powered by Google App Engine
This is Rietveld 408576698