Sprinkle a few strategic likely()'s
Shrinks the code size by some 2% even.
This commit is contained in:
parent
69cb28bc13
commit
4c20d8c057
|
@ -168,7 +168,7 @@ struct TTCHeader
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *context) {
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!u.header.version.sanitize (context)) return false;
|
if (unlikely (!u.header.version.sanitize (context))) return false;
|
||||||
switch (u.header.version) {
|
switch (u.header.version) {
|
||||||
case 2: /* version 2 is compatible with version 1 */
|
case 2: /* version 2 is compatible with version 1 */
|
||||||
case 1: return u.version1.sanitize (context);
|
case 1: return u.version1.sanitize (context);
|
||||||
|
@ -230,7 +230,7 @@ struct OpenTypeFontFile
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *context) {
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!u.tag.sanitize (context)) return false;
|
if (unlikely (!u.tag.sanitize (context))) return false;
|
||||||
switch (u.tag) {
|
switch (u.tag) {
|
||||||
case CFFTag: /* All the non-collection tags */
|
case CFFTag: /* All the non-collection tags */
|
||||||
case TrueTag:
|
case TrueTag:
|
||||||
|
|
|
@ -386,7 +386,7 @@ struct IntType
|
||||||
inline bool operator != (const IntType<Type> &o) const { return v != o.v; }
|
inline bool operator != (const IntType<Type> &o) const { return v != o.v; }
|
||||||
inline bool sanitize (hb_sanitize_context_t *context) {
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
return context->check_struct (this);
|
return likely (context->check_struct (this));
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
BEInt<Type, sizeof (Type)> v;
|
BEInt<Type, sizeof (Type)> v;
|
||||||
|
@ -482,7 +482,7 @@ struct GenericOffsetTo : OffsetType
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
|
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!context->check_struct (this)) return false;
|
if (unlikely (!context->check_struct (this))) return false;
|
||||||
unsigned int offset = *this;
|
unsigned int offset = *this;
|
||||||
if (unlikely (!offset)) return true;
|
if (unlikely (!offset)) return true;
|
||||||
Type &obj = StructAtOffset<Type> (base, offset);
|
Type &obj = StructAtOffset<Type> (base, offset);
|
||||||
|
@ -491,7 +491,7 @@ struct GenericOffsetTo : OffsetType
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool sanitize (hb_sanitize_context_t *context, void *base, T user_data) {
|
inline bool sanitize (hb_sanitize_context_t *context, void *base, T user_data) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!context->check_struct (this)) return false;
|
if (unlikely (!context->check_struct (this))) return false;
|
||||||
unsigned int offset = *this;
|
unsigned int offset = *this;
|
||||||
if (unlikely (!offset)) return true;
|
if (unlikely (!offset)) return true;
|
||||||
Type &obj = StructAtOffset<Type> (base, offset);
|
Type &obj = StructAtOffset<Type> (base, offset);
|
||||||
|
@ -547,7 +547,7 @@ struct GenericArrayOf
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *context) {
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!likely (sanitize_shallow (context))) return false;
|
if (unlikely (!sanitize_shallow (context))) return false;
|
||||||
/* Note: for structs that do not reference other structs,
|
/* Note: for structs that do not reference other structs,
|
||||||
* we do not need to call their sanitize() as we already did
|
* we do not need to call their sanitize() as we already did
|
||||||
* a bound check on the aggregate array size, hence the return.
|
* a bound check on the aggregate array size, hence the return.
|
||||||
|
@ -564,20 +564,20 @@ struct GenericArrayOf
|
||||||
}
|
}
|
||||||
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
|
inline bool sanitize (hb_sanitize_context_t *context, void *base) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!likely (sanitize_shallow (context))) return false;
|
if (unlikely (!sanitize_shallow (context))) return false;
|
||||||
unsigned int count = len;
|
unsigned int count = len;
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (!array[i].sanitize (context, base))
|
if (unlikely (!array[i].sanitize (context, base)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline bool sanitize (hb_sanitize_context_t *context, void *base, T user_data) {
|
inline bool sanitize (hb_sanitize_context_t *context, void *base, T user_data) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!likely (sanitize_shallow (context))) return false;
|
if (unlikely (!sanitize_shallow (context))) return false;
|
||||||
unsigned int count = len;
|
unsigned int count = len;
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (!array[i].sanitize (context, base, user_data))
|
if (unlikely (!array[i].sanitize (context, base, user_data)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -658,7 +658,7 @@ struct HeadlessArrayOf
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *context) {
|
inline bool sanitize (hb_sanitize_context_t *context) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
if (!likely (sanitize_shallow (context))) return false;
|
if (unlikely (!sanitize_shallow (context))) return false;
|
||||||
/* Note: for structs that do not reference other structs,
|
/* Note: for structs that do not reference other structs,
|
||||||
* we do not need to call their sanitize() as we already did
|
* we do not need to call their sanitize() as we already did
|
||||||
* a bound check on the aggregate array size, hence the return.
|
* a bound check on the aggregate array size, hence the return.
|
||||||
|
@ -670,7 +670,7 @@ struct HeadlessArrayOf
|
||||||
unsigned int count = len ? len - 1 : 0;
|
unsigned int count = len ? len - 1 : 0;
|
||||||
Type *a = array;
|
Type *a = array;
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (!a[i].sanitize (context))
|
if (unlikely (!a[i].sanitize (context)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue