Unify ART's various implementations of bit_cast.
ART had several implementations of art::bit_cast:
1. one in runtime/base/casts.h, declared as:
template <class Dest, class Source>
inline Dest bit_cast(const Source& source);
2. another one in runtime/utils.h, declared as:
template<typename U, typename V>
static inline V bit_cast(U in);
3. and a third local version, in runtime/memory_region.h,
similar to the previous one:
template<typename Source, typename Destination>
static Destination MemoryRegion::local_bit_cast(Source in);
This CL removes versions 2. and 3. and changes their callers
to use 1. instead. That version was chosen over the others
as:
- it was the oldest one in the code base; and
- its syntax was closer to the standard C++ cast operators,
as it supports the following use:
bit_cast<Destination>(source)
since `Source' can be deduced from `source'.
Change-Id: I7334fd5d55bf0b8a0c52cb33cfbae6894ff83633
diff --git a/test/457-regs/regs_jni.cc b/test/457-regs/regs_jni.cc
index ce701e8..1b32348 100644
--- a/test/457-regs/regs_jni.cc
+++ b/test/457-regs/regs_jni.cc
@@ -69,7 +69,7 @@
CHECK_EQ(value, 1u);
CHECK(GetVReg(m, 4, kFloatVReg, &value));
- uint32_t cast = bit_cast<float, uint32_t>(4.0f);
+ uint32_t cast = bit_cast<uint32_t, float>(4.0f);
CHECK_EQ(value, cast);
did_check_ = true;
} else if (m_name.compare("phiEquivalent") == 0) {
@@ -138,7 +138,7 @@
std::unique_ptr<Context> context(Context::Create());
CHECK(soa.Decode<mirror::Object*>(main) == nullptr);
CHECK_EQ(int_value, 0);
- int32_t cast = bit_cast<float, int32_t>(float_value);
+ int32_t cast = bit_cast<int32_t, float>(float_value);
CHECK_EQ(cast, 0);
TestVisitor visitor(soa.Self(), context.get());
visitor.WalkStack();