Chromium Code Reviews| Index: src/objects-inl.h |
| diff --git a/src/objects-inl.h b/src/objects-inl.h |
| index 58e4f7c666bec9af375ad458fc6d8bd5d08afc58..6cb0f9af7b5eb45c1da88d70086849451e346fbc 100644 |
| --- a/src/objects-inl.h |
| +++ b/src/objects-inl.h |
| @@ -689,6 +689,14 @@ int Smi::value() { |
| Smi* Smi::FromInt(int value) { |
| ASSERT(Smi::IsValid(value)); |
| + intptr_t tagged_value = |
| + (static_cast<intptr_t>(value) << kSmiTagSize) | kSmiTag; |
| + return reinterpret_cast<Smi*>(tagged_value); |
| +} |
| + |
| + |
| +Smi* Smi::FromIntptr(intptr_t value) { |
| + ASSERT(Smi::IsValid(value)); |
| return reinterpret_cast<Smi*>((value << kSmiTagSize) | kSmiTag); |
| } |
| @@ -784,6 +792,18 @@ bool Smi::IsValid(int value) { |
| } |
| +bool Smi::IsPtrValid(intptr_t value) { |
| +#ifdef DEBUG |
| + bool in_range = (value >= kMinValue) && (value <= kMaxValue); |
| +#endif |
| + // See Smi::IsValid(int) for description. |
| + bool result = |
| + ((static_cast<uintptr_t>(value) + 0x40000000U) < 0x80000000U); |
|
William Hesse
2009/05/06 07:42:37
If this is safe, why not change the test in IsVali
Lasse Reichstein
2009/05/12 08:16:38
Only the assumption that the and is slightly faste
|
| + ASSERT(result == in_range); |
| + return result; |
| +} |
| + |
| + |
| MapWord MapWord::FromMap(Map* map) { |
| return MapWord(reinterpret_cast<uintptr_t>(map)); |
| } |