Apply some minor improves on CFFIndex

pull/1804/head
Ebrahim Byagowi 5 years ago committed by GitHub
parent ddd29e5594
commit 3f806673fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      src/hb-ot-cff-common.hh

@ -92,9 +92,7 @@ struct CFFIndex
static unsigned int calculate_serialized_size (unsigned int offSize_, unsigned int count,
unsigned int dataSize)
{
if (count == 0)
return COUNT::static_size;
else
if (count == 0) return COUNT::static_size;
return min_size + calculate_offset_array_size (offSize_, count) + dataSize;
}
@ -159,9 +157,7 @@ struct CFFIndex
byteArray.init ();
byteArray.resize (buffArray.length);
for (unsigned int i = 0; i < byteArray.length; i++)
{
byteArray[i] = byte_str_t (buffArray[i].arrayZ, buffArray[i].length);
}
bool result = this->serialize (c, offSize_, byteArray);
byteArray.fini ();
return result;
@ -192,43 +188,35 @@ struct CFFIndex
unsigned int length_at (unsigned int index) const
{
if (likely ((offset_at (index + 1) >= offset_at (index)) &&
(offset_at (index + 1) <= offset_at (count))))
return offset_at (index + 1) - offset_at (index);
else
if (unlikely ((offset_at (index + 1) < offset_at (index)) ||
(offset_at (index + 1) > offset_at (count))))
return 0;
return offset_at (index + 1) - offset_at (index);
}
const unsigned char *data_base () const
{ return (const unsigned char *)this + min_size + offset_array_size (); }
{ return (const unsigned char *) this + min_size + offset_array_size (); }
unsigned int data_size () const { return HBINT8::static_size; }
byte_str_t operator [] (unsigned int index) const
{
if (likely (index < count))
if (unlikely (index >= count)) return Null (byte_str_t);
return byte_str_t (data_base () + offset_at (index) - 1, length_at (index));
else
return Null (byte_str_t);
}
unsigned int get_size () const
{
if (this != &Null (CFFIndex))
{
if (this == &Null (CFFIndex)) return 0;
if (count > 0)
return min_size + offset_array_size () + (offset_at (count) - 1);
else
return count.static_size; /* empty CFFIndex contains count only */
}
else
return 0;
}
bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (likely ((count.sanitize (c) && count == 0) || /* empty INDEX */
return_trace (likely ((c->check_struct (this) && count == 0) || /* empty INDEX */
(c->check_struct (this) && offSize >= 1 && offSize <= 4 &&
c->check_array (offsets, offSize, count + 1) &&
c->check_array ((const HBUINT8*) data_base (), 1, max_offset () - 1))));

Loading…
Cancel
Save