[cff] Optimize byte_str_ref_t

Make it 16 bytes instead of 24.  This struct is used in the subroutine
call stack heavily.

This change makes the HB AdobeVFPrototype benchmark to become faster
than FT one, with about 6% speedup as a result of this change.
This commit is contained in:
Behdad Esfahbod 2022-11-21 10:27:07 -07:00
parent 7a39464b18
commit b51ab1a9e5
1 changed files with 16 additions and 20 deletions

View File

@ -285,57 +285,53 @@ struct UnsizedByteStr : UnsizedArrayOf <HBUINT8>
struct byte_str_ref_t
{
byte_str_ref_t ()
: str (), offset (0), error (false) {}
: str () {}
byte_str_ref_t (const hb_ubytes_t &str_, unsigned int offset_ = 0)
: str (str_), offset (offset_), error (false) {}
: str (str_) { set_offset (offset_); }
void reset (const hb_ubytes_t &str_, unsigned int offset_ = 0)
{
str = str_;
offset = offset_;
error = false;
set_offset (offset_);
}
const unsigned char& operator [] (int i) {
if (unlikely ((unsigned int) (offset + i) >= str.length))
if (unlikely ((unsigned int) (get_offset () + i) >= str.length))
{
set_error ();
return Null (unsigned char);
}
return str[offset + i];
return str[get_offset () + i];
}
/* Conversion to hb_ubytes_t */
operator hb_ubytes_t () const { return str.sub_array (offset, str.length - offset); }
operator hb_ubytes_t () const { return str.sub_array (get_offset ()); }
hb_ubytes_t sub_array (unsigned int offset_, unsigned int len_) const
{ return str.sub_array (offset_, len_); }
bool avail (unsigned int count=1) const
{ return (!in_error () && offset + count <= str.length); }
{ return get_offset () + count <= str.length; }
void inc (unsigned int count=1)
{
if (likely (!in_error () && (offset <= str.length) && (offset + count <= str.length)))
{
offset += count;
}
if (get_offset () + count <= str.length)
set_offset (get_offset () + count);
else
{
offset = str.length;
set_error ();
}
}
unsigned get_offset () const { return offset; }
/* We (ab)use ubytes backwards_length as a cursor (called offset),
* as well as to store error condition. */
void set_error () { error = true; }
bool in_error () const { return error; }
unsigned get_offset () const { return str.backwards_length; }
void set_offset (unsigned offset) { str.backwards_length = offset; }
void set_error () { str.backwards_length = str.length + 1; }
bool in_error () const { return str.backwards_length > str.length; }
protected:
hb_ubytes_t str;
unsigned int offset; /* beginning of the sub-string within str */
bool error;
};
using byte_str_array_t = hb_vector_t<hb_ubytes_t>;