Minor cleanup, add LIKELY and UNLIKELY annotations

This commit is contained in:
Behdad Esfahbod 2008-01-23 15:50:38 -05:00
parent 8dd1c8b8d6
commit 12360f7c15
3 changed files with 63 additions and 51 deletions

View File

@ -3,6 +3,15 @@
#include "hb-ot-layout-open-private.h" #include "hb-ot-layout-open-private.h"
#define DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP(Type, name) \
inline const Type& name (uint16_t glyph_id) { \
const Coverage &c = get_coverage (); \
int c_index = c.get_coverage (glyph_id); \
return (*this)[c_index]; \
}
struct GlyphClassDef : ClassDef { struct GlyphClassDef : ClassDef {
static const uint16_t BaseGlyph = 0x0001u; static const uint16_t BaseGlyph = 0x0001u;
static const uint16_t LigatureGlyph = 0x0002u; static const uint16_t LigatureGlyph = 0x0002u;
@ -27,12 +36,8 @@ struct AttachPoint {
DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2); DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2);
struct AttachList { struct AttachList {
/* const AttachPoint& get_attach_points (uint16_t glyph_id); */
inline const AttachPoint* get_attach_points (uint16_t glyph_id) { DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, get_attach_points);
const Coverage &c = get_coverage ();
int c_index = c.get_coverage (glyph_id);
return &(*this)[c_index];
}
private: private:
/* AttachPoint tables, in Coverage Index order */ /* AttachPoint tables, in Coverage Index order */
@ -54,22 +59,6 @@ DEFINE_NULL_ASSERT_SIZE (AttachList, 4);
* Ligature Caret Table * Ligature Caret Table
*/ */
struct CaretValue;
struct LigCaretList {
/* TODO */
private:
Offset coverage; /* Offset to Coverage table--from
* beginning of LigCaretList table */
USHORT ligGlyphCount; /* Number of ligature glyphs */
Offset ligGlyph[]; /* Array of offsets to LigGlyph
* tables--from beginning of
* LigCaretList table--in Coverage
* Index order */
};
DEFINE_NULL_ASSERT_SIZE (LigCaretList, 4);
struct CaretValueFormat1 { struct CaretValueFormat1 {
inline int get_caret_value (int ppem) const { inline int get_caret_value (int ppem) const {
@ -80,7 +69,7 @@ struct CaretValueFormat1 {
USHORT caretValueFormat; /* Format identifier--format = 1 */ USHORT caretValueFormat; /* Format identifier--format = 1 */
SHORT coordinate; /* X or Y value, in design units */ SHORT coordinate; /* X or Y value, in design units */
}; };
DEFINE_NULL_ASSERT_SIZE (CaretValueFormat1, 4); ASSERT_SIZE (CaretValueFormat1, 4);
struct CaretValueFormat2 { struct CaretValueFormat2 {
@ -92,12 +81,12 @@ struct CaretValueFormat2 {
USHORT caretValueFormat; /* Format identifier--format = 2 */ USHORT caretValueFormat; /* Format identifier--format = 2 */
USHORT caretValuePoint; /* Contour point index on glyph */ USHORT caretValuePoint; /* Contour point index on glyph */
}; };
DEFINE_NULL_ASSERT_SIZE (CaretValueFormat2, 4); ASSERT_SIZE (CaretValueFormat2, 4);
struct CaretValueFormat3 { struct CaretValueFormat3 {
inline const Device& get_device (void) const { inline const Device& get_device (void) const {
if (!deviceTable) return NullDevice; if (HB_UNLIKELY (!deviceTable)) return NullDevice;
return *(const Device*)((const char*)this + deviceTable); return *(const Device*)((const char*)this + deviceTable);
} }
@ -112,7 +101,7 @@ struct CaretValueFormat3 {
* value--from beginning of CaretValue * value--from beginning of CaretValue
* table */ * table */
}; };
DEFINE_NULL_ASSERT_SIZE (CaretValueFormat3, 6); ASSERT_SIZE (CaretValueFormat3, 6);
struct CaretValue { struct CaretValue {
DEFINE_NON_INSTANTIABLE(CaretValue); DEFINE_NON_INSTANTIABLE(CaretValue);
@ -162,6 +151,26 @@ struct LigGlyph {
}; };
DEFINE_NULL_ASSERT_SIZE (LigGlyph, 2); DEFINE_NULL_ASSERT_SIZE (LigGlyph, 2);
struct LigCaretList {
/* const LigGlyph& get_lig_glyph (uint16_t glyph_id); */
DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (LigGlyph, get_lig_glyph);
private:
/* AttachPoint tables, in Coverage Index order */
DEFINE_OFFSET_ARRAY_TYPE (LigGlyph, ligGlyph, ligGlyphCount);
DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
private:
Offset coverage; /* Offset to Coverage table--from
* beginning of LigCaretList table */
USHORT ligGlyphCount; /* Number of ligature glyphs */
Offset ligGlyph[]; /* Array of offsets to LigGlyph
* tables--from beginning of
* LigCaretList table--in Coverage
* Index order */
};
DEFINE_NULL_ASSERT_SIZE (LigCaretList, 4);
/* /*
* GDEF Header * GDEF Header
*/ */

View File

@ -4,18 +4,6 @@
#include "hb-private.h" #include "hb-private.h"
#include "hb-ot-layout.h" #include "hb-ot-layout.h"
#include <glib.h>
/* Macros to convert to/from BigEndian */
#define hb_be_uint8_t
#define hb_be_int8_t
#define hb_be_uint16_t GUINT16_TO_BE
#define hb_be_int16_t GINT16_TO_BE
#define hb_be_uint32_t GUINT32_TO_BE
#define hb_be_int32_t GINT32_TO_BE
#define hb_be_uint64_t GUINT64_TO_BE
#define hb_be_int64_t GINT64_TO_BE
/* /*
* Int types * Int types
*/ */
@ -57,7 +45,7 @@
DEFINE_LEN_AND_SIZE(Type, array, num) DEFINE_LEN_AND_SIZE(Type, array, num)
#define DEFINE_INDEX_OPERATOR(Type, array, num) \ #define DEFINE_INDEX_OPERATOR(Type, array, num) \
inline const Type& operator[] (unsigned int i) const { \ inline const Type& operator[] (unsigned int i) const { \
if (i >= num) return Null##Type; \ if (HB_UNLIKELY (i >= num)) return Null##Type; \
return array[i]; \ return array[i]; \
} }
@ -69,8 +57,8 @@
DEFINE_LEN_AND_SIZE(Offset, array, num) DEFINE_LEN_AND_SIZE(Offset, array, num)
#define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \ #define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
inline const Type& operator[] (unsigned int i) const { \ inline const Type& operator[] (unsigned int i) const { \
if (i >= num) return Null##Type; \ if (HB_UNLIKELY (i >= num)) return Null##Type; \
if (!array[i]) return Null##Type; \ if (HB_UNLIKELY (!array[i])) return Null##Type; \
return *(const Type *)((const char*)this + array[i]); \ return *(const Type *)((const char*)this + array[i]); \
} }
@ -79,12 +67,12 @@
DEFINE_LEN_AND_SIZE(Record, array, num) DEFINE_LEN_AND_SIZE(Record, array, num)
#define DEFINE_RECORD_ACCESSOR(Type, array, num) \ #define DEFINE_RECORD_ACCESSOR(Type, array, num) \
inline const Type& operator[] (unsigned int i) const { \ inline const Type& operator[] (unsigned int i) const { \
if (i >= num) return Null##Type; \ if (HB_UNLIKELY (i >= num)) return Null##Type; \
if (!array[i].offset) return Null##Type; \ if (HB_UNLIKELY (!array[i].offset)) return Null##Type; \
return *(const Type *)((const char*)this + array[i].offset); \ return *(const Type *)((const char*)this + array[i].offset); \
} \ } \
inline const Tag& get_tag (unsigned int i) const { \ inline const Tag& get_tag (unsigned int i) const { \
if (i >= num) return NullTag; \ if (HB_UNLIKELY (i >= num)) return NullTag; \
return array[i].tag; \ return array[i].tag; \
} \ } \
/* TODO: implement find_tag() */ /* TODO: implement find_tag() */
@ -95,7 +83,7 @@
#define DEFINE_LIST_ACCESSOR(Type, name) \ #define DEFINE_LIST_ACCESSOR(Type, name) \
inline const Type##List& get_##name##_list (void) const { \ inline const Type##List& get_##name##_list (void) const { \
if (!name##List) return Null##Type##List; \ if (HB_UNLIKELY (!name##List)) return Null##Type##List; \
return *(const Type##List *)((const char*)this + name##List); \ return *(const Type##List *)((const char*)this + name##List); \
} \ } \
inline const Type& get_##name (unsigned int i) const { \ inline const Type& get_##name (unsigned int i) const { \
@ -140,7 +128,7 @@
#define DEFINE_ACCESSOR(Type, name, Name) \ #define DEFINE_ACCESSOR(Type, name, Name) \
inline const Type& name (void) const { \ inline const Type& name (void) const { \
if (!Name) return Null##Type; \ if (HB_UNLIKELY (!Name)) return Null##Type; \
return *(const Type*)((const char*)this + Name); \ return *(const Type*)((const char*)this + Name); \
} }
@ -368,7 +356,7 @@ struct OpenTypeFontFile {
} }
} }
inline const OpenTypeFontFace& operator[] (unsigned int i) const { inline const OpenTypeFontFace& operator[] (unsigned int i) const {
if (i >= get_len ()) return NullOpenTypeFontFace; if (HB_UNLIKELY (i >= get_len ())) return NullOpenTypeFontFace;
switch (tag) { switch (tag) {
default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this; default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this;
case TTCTag: return ((const TTCHeader&)*this)[i]; case TTCTag: return ((const TTCHeader&)*this)[i];
@ -435,7 +423,7 @@ struct Script {
return defaultLangSys != 0; return defaultLangSys != 0;
} }
inline const LangSys& get_default_language_system (void) const { inline const LangSys& get_default_language_system (void) const {
if (!defaultLangSys) if (HB_UNLIKELY (!defaultLangSys))
return NullLangSys; return NullLangSys;
return *(LangSys*)((const char*)this + defaultLangSys); return *(LangSys*)((const char*)this + defaultLangSys);
} }
@ -557,7 +545,7 @@ struct CoverageFormat1 {
GlyphID gid; GlyphID gid;
gid = glyph_id; gid = glyph_id;
// TODO: bsearch // TODO: bsearch
for (int i = 0; i < glyphCount; i++) for (unsigned int i = 0; i < glyphCount; i++)
if (gid == glyphArray[i]) if (gid == glyphArray[i])
return i; return i;
return -1; return -1;
@ -592,7 +580,7 @@ struct CoverageFormat2 {
inline int get_coverage (uint16_t glyph_id) const { inline int get_coverage (uint16_t glyph_id) const {
// TODO: bsearch // TODO: bsearch
for (int i = 0; i < rangeCount; i++) { for (unsigned int i = 0; i < rangeCount; i++) {
int coverage = rangeRecord[i].get_coverage (glyph_id); int coverage = rangeRecord[i].get_coverage (glyph_id);
if (coverage >= 0) if (coverage >= 0)
return coverage; return coverage;

View File

@ -1,6 +1,21 @@
#ifndef HB_PRIVATE_H #ifndef HB_PRIVATE_H
#define HB_PRIVATE_H #define HB_PRIVATE_H
#include <glib.h>
/* Macros to convert to/from BigEndian */
#define hb_be_uint8_t
#define hb_be_int8_t
#define hb_be_uint16_t GUINT16_TO_BE
#define hb_be_int16_t GINT16_TO_BE
#define hb_be_uint32_t GUINT32_TO_BE
#define hb_be_int32_t GINT32_TO_BE
#define hb_be_uint64_t GUINT64_TO_BE
#define hb_be_int64_t GINT64_TO_BE
#define HB_LIKELY G_LIKEYLY
#define HB_UNLIKELY G_UNLIKELY
#include <assert.h> #include <assert.h>
#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] #define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]