From c46196d09c4ea879bf45182e8a0d649d4c750c39 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 27 Dec 2006 20:05:16 -0500 Subject: [PATCH] Use union for Coverage --- src/harfbuzz-ng.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/harfbuzz-ng.cc b/src/harfbuzz-ng.cc index 97014f994..47d7ebe43 100644 --- a/src/harfbuzz-ng.cc +++ b/src/harfbuzz-ng.cc @@ -25,8 +25,6 @@ typedef uint32_t hb_tag_t; */ #define DEFINE_INT_TYPE1(NAME, TYPE, BIG_ENDIAN) \ - inline NAME (void) { v = 0; } \ - explicit inline NAME (TYPE i) { v = BIG_ENDIAN(i); } \ inline NAME& operator = (TYPE i) { v = BIG_ENDIAN(i); return *this; } \ inline operator TYPE(void) const { return BIG_ENDIAN(v); } \ inline bool operator== (NAME o) const { return v == o.v; } \ @@ -463,7 +461,8 @@ struct CoverageFormat1 { DEFINE_ARRAY_TYPE (GlyphID, glyphArray, glyphCount); inline int get_coverage (uint16_t glyph_id) const { - GlyphID gid (glyph_id); + GlyphID gid; + gid = glyph_id; // TODO: bsearch for (int i = 0; i < glyphCount; i++) if (gid == glyphArray[i]) @@ -511,27 +510,29 @@ struct CoverageFormat2 { * long */ }; -struct Coverage { +union Coverage { DEFINE_NON_INSTANTIABLE(Coverage); inline unsigned int get_size (void) const { switch (coverageFormat) { - case 1: return ((const CoverageFormat1&)*this).get_size (); - case 2: return ((const CoverageFormat2&)*this).get_size (); - default:return sizeof (Coverage); + case 1: return format1.get_size (); + case 2: return format2.get_size (); + default:return sizeof (coverageFormat); } } /* Returns -1 if not covered. */ inline int get_coverage (uint16_t glyph_id) const { switch (coverageFormat) { - case 1: return ((const CoverageFormat1&)*this).get_coverage(glyph_id); - case 2: return ((const CoverageFormat2&)*this).get_coverage(glyph_id); + case 1: return format1.get_coverage(glyph_id); + case 2: return format2.get_coverage(glyph_id); default:return -1; } } - USHORT coverageFormat; /* Format identifier */ + USHORT coverageFormat; /* Format identifier */ + CoverageFormat1 format1; + CoverageFormat2 format2; }; /*