Minor cleanup, add LIKELY and UNLIKELY annotations
This commit is contained in:
parent
8dd1c8b8d6
commit
12360f7c15
@ -3,6 +3,15 @@
|
||||
|
||||
#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 {
|
||||
static const uint16_t BaseGlyph = 0x0001u;
|
||||
static const uint16_t LigatureGlyph = 0x0002u;
|
||||
@ -27,19 +36,15 @@ struct AttachPoint {
|
||||
DEFINE_NULL_ASSERT_SIZE (AttachPoint, 2);
|
||||
|
||||
struct AttachList {
|
||||
|
||||
inline const AttachPoint* get_attach_points (uint16_t glyph_id) {
|
||||
const Coverage &c = get_coverage ();
|
||||
int c_index = c.get_coverage (glyph_id);
|
||||
return &(*this)[c_index];
|
||||
}
|
||||
/* const AttachPoint& get_attach_points (uint16_t glyph_id); */
|
||||
DEFINE_INDIRECT_GLYPH_ARRAY_LOOKUP (AttachPoint, get_attach_points);
|
||||
|
||||
private:
|
||||
/* AttachPoint tables, in Coverage Index order */
|
||||
DEFINE_OFFSET_ARRAY_TYPE (AttachPoint, attachPoint, glyphCount);
|
||||
DEFINE_ACCESSOR (Coverage, get_coverage, coverage);
|
||||
|
||||
private:
|
||||
private:
|
||||
Offset coverage; /* Offset to Coverage table -- from
|
||||
* beginning of AttachList table */
|
||||
USHORT glyphCount; /* Number of glyphs with attachment
|
||||
@ -54,22 +59,6 @@ DEFINE_NULL_ASSERT_SIZE (AttachList, 4);
|
||||
* 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 {
|
||||
|
||||
inline int get_caret_value (int ppem) const {
|
||||
@ -80,7 +69,7 @@ struct CaretValueFormat1 {
|
||||
USHORT caretValueFormat; /* Format identifier--format = 1 */
|
||||
SHORT coordinate; /* X or Y value, in design units */
|
||||
};
|
||||
DEFINE_NULL_ASSERT_SIZE (CaretValueFormat1, 4);
|
||||
ASSERT_SIZE (CaretValueFormat1, 4);
|
||||
|
||||
struct CaretValueFormat2 {
|
||||
|
||||
@ -92,12 +81,12 @@ struct CaretValueFormat2 {
|
||||
USHORT caretValueFormat; /* Format identifier--format = 2 */
|
||||
USHORT caretValuePoint; /* Contour point index on glyph */
|
||||
};
|
||||
DEFINE_NULL_ASSERT_SIZE (CaretValueFormat2, 4);
|
||||
ASSERT_SIZE (CaretValueFormat2, 4);
|
||||
|
||||
struct CaretValueFormat3 {
|
||||
|
||||
inline const Device& get_device (void) const {
|
||||
if (!deviceTable) return NullDevice;
|
||||
if (HB_UNLIKELY (!deviceTable)) return NullDevice;
|
||||
return *(const Device*)((const char*)this + deviceTable);
|
||||
}
|
||||
|
||||
@ -112,7 +101,7 @@ struct CaretValueFormat3 {
|
||||
* value--from beginning of CaretValue
|
||||
* table */
|
||||
};
|
||||
DEFINE_NULL_ASSERT_SIZE (CaretValueFormat3, 6);
|
||||
ASSERT_SIZE (CaretValueFormat3, 6);
|
||||
|
||||
struct CaretValue {
|
||||
DEFINE_NON_INSTANTIABLE(CaretValue);
|
||||
@ -162,6 +151,26 @@ struct LigGlyph {
|
||||
};
|
||||
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
|
||||
*/
|
||||
|
@ -4,18 +4,6 @@
|
||||
#include "hb-private.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
|
||||
*/
|
||||
@ -57,7 +45,7 @@
|
||||
DEFINE_LEN_AND_SIZE(Type, array, num)
|
||||
#define DEFINE_INDEX_OPERATOR(Type, array, num) \
|
||||
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]; \
|
||||
}
|
||||
|
||||
@ -69,8 +57,8 @@
|
||||
DEFINE_LEN_AND_SIZE(Offset, array, num)
|
||||
#define DEFINE_OFFSET_INDEX_OPERATOR(Type, array, num) \
|
||||
inline const Type& operator[] (unsigned int i) const { \
|
||||
if (i >= num) return Null##Type; \
|
||||
if (!array[i]) return Null##Type; \
|
||||
if (HB_UNLIKELY (i >= num)) return Null##Type; \
|
||||
if (HB_UNLIKELY (!array[i])) return Null##Type; \
|
||||
return *(const Type *)((const char*)this + array[i]); \
|
||||
}
|
||||
|
||||
@ -79,12 +67,12 @@
|
||||
DEFINE_LEN_AND_SIZE(Record, array, num)
|
||||
#define DEFINE_RECORD_ACCESSOR(Type, array, num) \
|
||||
inline const Type& operator[] (unsigned int i) const { \
|
||||
if (i >= num) return Null##Type; \
|
||||
if (!array[i].offset) return Null##Type; \
|
||||
if (HB_UNLIKELY (i >= num)) return Null##Type; \
|
||||
if (HB_UNLIKELY (!array[i].offset)) return Null##Type; \
|
||||
return *(const Type *)((const char*)this + array[i].offset); \
|
||||
} \
|
||||
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; \
|
||||
} \
|
||||
/* TODO: implement find_tag() */
|
||||
@ -95,7 +83,7 @@
|
||||
|
||||
#define DEFINE_LIST_ACCESSOR(Type, name) \
|
||||
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); \
|
||||
} \
|
||||
inline const Type& get_##name (unsigned int i) const { \
|
||||
@ -140,7 +128,7 @@
|
||||
|
||||
#define DEFINE_ACCESSOR(Type, name, Name) \
|
||||
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); \
|
||||
}
|
||||
|
||||
@ -368,7 +356,7 @@ struct OpenTypeFontFile {
|
||||
}
|
||||
}
|
||||
inline const OpenTypeFontFace& operator[] (unsigned int i) const {
|
||||
if (i >= get_len ()) return NullOpenTypeFontFace;
|
||||
if (HB_UNLIKELY (i >= get_len ())) return NullOpenTypeFontFace;
|
||||
switch (tag) {
|
||||
default: case TrueTypeTag: case CFFTag: return (const OffsetTable&)*this;
|
||||
case TTCTag: return ((const TTCHeader&)*this)[i];
|
||||
@ -435,7 +423,7 @@ struct Script {
|
||||
return defaultLangSys != 0;
|
||||
}
|
||||
inline const LangSys& get_default_language_system (void) const {
|
||||
if (!defaultLangSys)
|
||||
if (HB_UNLIKELY (!defaultLangSys))
|
||||
return NullLangSys;
|
||||
return *(LangSys*)((const char*)this + defaultLangSys);
|
||||
}
|
||||
@ -557,7 +545,7 @@ struct CoverageFormat1 {
|
||||
GlyphID gid;
|
||||
gid = glyph_id;
|
||||
// TODO: bsearch
|
||||
for (int i = 0; i < glyphCount; i++)
|
||||
for (unsigned int i = 0; i < glyphCount; i++)
|
||||
if (gid == glyphArray[i])
|
||||
return i;
|
||||
return -1;
|
||||
@ -592,7 +580,7 @@ struct CoverageFormat2 {
|
||||
|
||||
inline int get_coverage (uint16_t glyph_id) const {
|
||||
// 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);
|
||||
if (coverage >= 0)
|
||||
return coverage;
|
||||
|
@ -1,6 +1,21 @@
|
||||
#ifndef 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>
|
||||
|
||||
#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
|
||||
|
Loading…
Reference in New Issue
Block a user