[machinery] Remove CastP

This commit is contained in:
Behdad Esfahbod 2019-12-10 13:02:48 -06:00
parent 85574ec287
commit b84ceb2fcf
3 changed files with 7 additions and 13 deletions

View File

@ -49,14 +49,6 @@ template<typename Type, typename TObject>
static inline Type& CastR(TObject &X) static inline Type& CastR(TObject &X)
{ return reinterpret_cast<Type&> (X); } { return reinterpret_cast<Type&> (X); }
/* Cast to struct T, pointer to pointer */
template<typename Type, typename TObject>
static inline const Type* CastP(const TObject *X)
{ return reinterpret_cast<const Type*> (X); }
template<typename Type, typename TObject>
static inline Type* CastP(TObject *X)
{ return reinterpret_cast<Type*> (X); }
/* StructAtOffset<T>(P,Ofs) returns the struct T& that is placed at memory /* StructAtOffset<T>(P,Ofs) returns the struct T& that is placed at memory
* location pointed to by P plus Ofs bytes. */ * location pointed to by P plus Ofs bytes. */
template<typename Type> template<typename Type>

View File

@ -174,17 +174,19 @@ struct ValueFormat : HBUINT16
} }
HB_INTERNAL static OffsetTo<Device>& get_device (Value* value) HB_INTERNAL static OffsetTo<Device>& get_device (Value* value)
{ return *CastP<OffsetTo<Device>> (value); } {
return *static_cast<OffsetTo<Device> *> (value);
}
HB_INTERNAL static const OffsetTo<Device>& get_device (const Value* value, bool *worked=nullptr) HB_INTERNAL static const OffsetTo<Device>& get_device (const Value* value, bool *worked=nullptr)
{ {
if (worked) *worked |= bool (*value); if (worked) *worked |= bool (*value);
return *CastP<OffsetTo<Device>> (value); return *static_cast<const OffsetTo<Device> *> (value);
} }
HB_INTERNAL static const HBINT16& get_short (const Value* value, bool *worked=nullptr) HB_INTERNAL static const HBINT16& get_short (const Value* value, bool *worked=nullptr)
{ {
if (worked) *worked |= bool (*value); if (worked) *worked |= bool (*value);
return *CastP<HBINT16> (value); return *reinterpret_cast<const HBINT16 *> (value);
} }
public: public:

View File

@ -115,7 +115,7 @@ main (int argc, char **argv)
case HB_OT_TAG_GPOS: case HB_OT_TAG_GPOS:
{ {
const GSUBGPOS &g = *CastP<GSUBGPOS> (font_data + table.offset); const GSUBGPOS &g = *reinterpret_cast<const GSUBGPOS *> (font_data + table.offset);
int num_scripts = g.get_script_count (); int num_scripts = g.get_script_count ();
printf (" %d script(s) found in table\n", num_scripts); printf (" %d script(s) found in table\n", num_scripts);
@ -185,7 +185,7 @@ main (int argc, char **argv)
case GDEF::tableTag: case GDEF::tableTag:
{ {
const GDEF &gdef = *CastP<GDEF> (font_data + table.offset); const GDEF &gdef = *reinterpret_cast<const GDEF *> (font_data + table.offset);
printf (" Has %sglyph classes\n", printf (" Has %sglyph classes\n",
gdef.has_glyph_classes () ? "" : "no "); gdef.has_glyph_classes () ? "" : "no ");