Simplify array access
This commit is contained in:
parent
54842374c2
commit
b961518b96
@ -89,7 +89,6 @@ inline Type& StructAfter(TObject &X)
|
||||
|
||||
#define DEFINE_SIZE_STATIC(size) \
|
||||
_DEFINE_SIZE_ASSERTION (size); \
|
||||
static inline unsigned int get_size (void) { return (size); } \
|
||||
static const unsigned int static_size = (size); \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
@ -515,9 +514,6 @@ struct LongOffsetTo : GenericOffsetTo<LongOffset, Type> {};
|
||||
template <typename LenType, typename Type>
|
||||
struct GenericArrayOf
|
||||
{
|
||||
const Type *array(void) const { return &StructAfter<Type> (len); }
|
||||
Type *array(void) { return &StructAfter<Type> (len); }
|
||||
|
||||
const Type *sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const
|
||||
{
|
||||
unsigned int count = len;
|
||||
@ -527,13 +523,13 @@ struct GenericArrayOf
|
||||
count -= start_offset;
|
||||
count = MIN (count, *pcount);
|
||||
*pcount = count;
|
||||
return array() + start_offset;
|
||||
return array + start_offset;
|
||||
}
|
||||
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
if (unlikely (i >= len)) return Null(Type);
|
||||
return array()[i];
|
||||
return array[i];
|
||||
}
|
||||
inline unsigned int get_size () const
|
||||
{ return len.static_size + len * Type::static_size; }
|
||||
@ -551,7 +547,7 @@ struct GenericArrayOf
|
||||
* other structs. */
|
||||
unsigned int count = len;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (array()[i].sanitize (context))
|
||||
if (array[i].sanitize (context))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -560,7 +556,7 @@ struct GenericArrayOf
|
||||
if (!likely (sanitize_shallow (context))) return false;
|
||||
unsigned int count = len;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (!array()[i].sanitize (context, base))
|
||||
if (!array[i].sanitize (context, base))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -570,7 +566,7 @@ struct GenericArrayOf
|
||||
if (!likely (sanitize_shallow (context))) return false;
|
||||
unsigned int count = len;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (!array()[i].sanitize (context, base, user_data))
|
||||
if (!array[i].sanitize (context, base, user_data))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -584,8 +580,7 @@ struct GenericArrayOf
|
||||
|
||||
public:
|
||||
LenType len;
|
||||
private:
|
||||
Type arrayX[VAR];
|
||||
Type array[VAR];
|
||||
public:
|
||||
DEFINE_SIZE_VAR (sizeof (LenType), Type);
|
||||
};
|
||||
@ -617,7 +612,7 @@ struct OffsetListOf : OffsetArrayOf<Type>
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
if (unlikely (i >= this->len)) return Null(Type);
|
||||
return this+this->array()[i];
|
||||
return this+this->array[i];
|
||||
}
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *context) {
|
||||
@ -637,13 +632,10 @@ struct OffsetListOf : OffsetArrayOf<Type>
|
||||
template <typename Type>
|
||||
struct HeadlessArrayOf
|
||||
{
|
||||
const Type *array(void) const { return &StructAfter<Type> (len); }
|
||||
Type *array(void) { return &StructAfter<Type> (len); }
|
||||
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
if (unlikely (i >= len || !i)) return Null(Type);
|
||||
return array()[i-1];
|
||||
return array[i-1];
|
||||
}
|
||||
inline unsigned int get_size () const
|
||||
{ return len.static_size + (len ? len - 1 : 0) * Type::static_size; }
|
||||
@ -665,7 +657,7 @@ struct HeadlessArrayOf
|
||||
* to do have a simple sanitize(), ie. they do not reference
|
||||
* other structs. */
|
||||
unsigned int count = len ? len - 1 : 0;
|
||||
Type *a = array();
|
||||
Type *a = array;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (!a[i].sanitize (context))
|
||||
return false;
|
||||
@ -673,8 +665,7 @@ struct HeadlessArrayOf
|
||||
}
|
||||
|
||||
USHORT len;
|
||||
private:
|
||||
Type arrayX[VAR];
|
||||
Type array[VAR];
|
||||
public:
|
||||
DEFINE_SIZE_VAR (sizeof (USHORT), Type);
|
||||
};
|
||||
|
@ -89,7 +89,7 @@ struct RecordArrayOf : ArrayOf<Record<Type> > {
|
||||
Tag t;
|
||||
t.set (tag);
|
||||
/* TODO: bsearch (need to sort in sanitize) */
|
||||
const Record<Type> *a = this->array();
|
||||
const Record<Type> *a = this->array;
|
||||
unsigned int count = this->len;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
{
|
||||
@ -123,7 +123,7 @@ struct IndexArray : ArrayOf<USHORT>
|
||||
{
|
||||
if (unlikely (i >= this->len))
|
||||
return NO_INDEX;
|
||||
return this->array()[i];
|
||||
return this->array[i];
|
||||
}
|
||||
inline unsigned int get_indexes (unsigned int start_offset,
|
||||
unsigned int *_count /* IN/OUT */,
|
||||
@ -600,8 +600,8 @@ struct Device
|
||||
inline unsigned int get_size () const
|
||||
{
|
||||
unsigned int f = deltaFormat;
|
||||
if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::get_size ();
|
||||
return USHORT::get_size () * (4 + ((endSize - startSize) >> (4 - f)));
|
||||
if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::static_size;
|
||||
return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f)));
|
||||
}
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *context) {
|
||||
|
@ -167,7 +167,7 @@ struct Sequence
|
||||
return false;
|
||||
|
||||
_hb_buffer_add_output_glyphs_be16 (context->buffer, 1,
|
||||
substitute.len, (const uint16_t *) substitute.array(),
|
||||
substitute.len, (const uint16_t *) substitute.array,
|
||||
0xFFFF, 0xFFFF);
|
||||
|
||||
/* This is a guess only ... */
|
||||
@ -616,10 +616,10 @@ struct ReverseChainSingleSubstFormat1
|
||||
const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
|
||||
|
||||
if (match_backtrack (context,
|
||||
backtrack.len, (USHORT *) backtrack.array(),
|
||||
backtrack.len, (USHORT *) backtrack.array,
|
||||
match_coverage, this) &&
|
||||
match_lookahead (context,
|
||||
lookahead.len, (USHORT *) lookahead.array(),
|
||||
lookahead.len, (USHORT *) lookahead.array,
|
||||
match_coverage, this,
|
||||
1))
|
||||
{
|
||||
|
@ -560,10 +560,10 @@ struct ChainRule
|
||||
const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input);
|
||||
const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead);
|
||||
return chain_context_lookup (context,
|
||||
backtrack.len, backtrack.array(),
|
||||
input.len, input.array(),
|
||||
lookahead.len, lookahead.array(),
|
||||
lookup.len, lookup.array(),
|
||||
backtrack.len, backtrack.array,
|
||||
input.len, input.array,
|
||||
lookahead.len, lookahead.array,
|
||||
lookup.len, lookup.array,
|
||||
lookup_context);
|
||||
return false;
|
||||
}
|
||||
@ -749,10 +749,10 @@ struct ChainContextFormat3
|
||||
{this, this, this}
|
||||
};
|
||||
return chain_context_lookup (context,
|
||||
backtrack.len, (const USHORT *) backtrack.array(),
|
||||
input.len, (const USHORT *) input.array() + 1,
|
||||
lookahead.len, (const USHORT *) lookahead.array(),
|
||||
lookup.len, lookup.array(),
|
||||
backtrack.len, (const USHORT *) backtrack.array,
|
||||
input.len, (const USHORT *) input.array + 1,
|
||||
lookahead.len, (const USHORT *) lookahead.array,
|
||||
lookup.len, lookup.array,
|
||||
lookup_context);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user