Revert "[cff-common] Optimize INDEX::operator[]"

This reverts commit 9edb03ac7a.
This commit is contained in:
Behdad Esfahbod 2022-05-10 14:54:04 -06:00
parent b31ef081db
commit 3aace2431b
1 changed files with 9 additions and 9 deletions

View File

@ -212,6 +212,14 @@ struct CFFIndex
return offset; return offset;
} }
unsigned int length_at (unsigned int index) const
{
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 const unsigned char *data_base () const
{ return (const unsigned char *) this + min_size + offSize.static_size + offset_array_size (); } { return (const unsigned char *) this + min_size + offSize.static_size + offset_array_size (); }
public: public:
@ -219,15 +227,7 @@ struct CFFIndex
hb_ubytes_t operator [] (unsigned int index) const hb_ubytes_t operator [] (unsigned int index) const
{ {
if (unlikely (index >= count)) return hb_ubytes_t (); if (unlikely (index >= count)) return hb_ubytes_t ();
return hb_ubytes_t (data_base () + offset_at (index) - 1, length_at (index));
unsigned offset1 = offset_at (index);
unsigned offset2 = offset_at (index + 1);
unsigned offsetn = offset_at (count);
if (unlikely (offset2 < offset1 || offset2 > offsetn))
return hb_ubytes_t ();
return hb_ubytes_t (data_base () + offset1 - 1, offset2 - offset1);
} }
unsigned int get_size () const unsigned int get_size () const