Chromium Code Reviews| Index: runtime/vm/assembler.h |
| =================================================================== |
| --- runtime/vm/assembler.h (revision 42801) |
| +++ runtime/vm/assembler.h (working copy) |
| @@ -205,6 +205,57 @@ |
| friend class AssemblerFixup; |
| }; |
| + |
| +// Pair type parameter for DirectChainedHashMap used for the constant pool. |
| +class ObjIndexPair { |
| + public: |
| + // Typedefs needed for the DirectChainedHashMap template. |
| + typedef const Object* Key; |
| + typedef intptr_t Value; |
| + typedef ObjIndexPair Pair; |
| + |
| + explicit ObjIndexPair(Value value) : key_(NULL), value_(NoValue()) { } |
|
Vyacheslav Egorov (Google)
2015/01/13 13:47:30
I think parameter is redundant. Just provide defau
Florian Schneider
2015/01/13 14:09:08
Done.
|
| + |
| + ObjIndexPair(Key key, Value value) |
| + : key_(key->IsNotTemporaryScopedHandle() |
| + ? key : &Object::ZoneHandle(key->raw())), |
| + value_(value) { } |
| + |
| + static Key KeyOf(Pair kv) { return kv.key_; } |
| + |
| + static Value ValueOf(Pair kv) { return kv.value_; } |
| + |
| + static Value NoValue() { return -1; } |
| + |
| + static intptr_t Hashcode(Key key) { |
| + if (key->IsSmi()) { |
| + return Smi::Cast(*key).Value(); |
| + } |
| + if (key->IsDouble()) { |
| + return static_cast<intptr_t>( |
| + bit_cast<int32_t, float>( |
| + static_cast<float>(Double::Cast(*key).value()))); |
| + } |
| + if (key->IsMint()) { |
| + return static_cast<intptr_t>(Mint::Cast(*key).value()); |
| + } |
| + if (key->IsString()) { |
| + return String::Cast(*key).Hash(); |
| + } |
| + // TODO(fschneider): Add hash function for other classes commonly used as |
| + // compile-time constants. |
| + return key->GetClassId(); |
| + } |
| + |
| + static inline bool IsKeyEqual(Pair kv, Key key) { |
| + return kv.key_->raw() == key->raw(); |
| + } |
| + |
| + private: |
| + Key key_; |
| + Value value_; |
| +}; |
| + |
| } // namespace dart |