Merge pull request #2875 from harfbuzz/constexpr-inttype
[constexpr] Add constructors to IntType
This commit is contained in:
commit
93745f9f49
|
@ -576,7 +576,7 @@ struct StateTable
|
||||||
if (unlikely (stop > states))
|
if (unlikely (stop > states))
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
for (const HBUSHORT *p = states; stop < p; p--)
|
for (const HBUSHORT *p = states; stop < p; p--)
|
||||||
num_entries = hb_max (num_entries, *(p - 1) + 1);
|
num_entries = hb_max (num_entries, *(p - 1) + 1u);
|
||||||
state_neg = min_state;
|
state_neg = min_state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ struct StateTable
|
||||||
if (unlikely (stop < states))
|
if (unlikely (stop < states))
|
||||||
return_trace (false);
|
return_trace (false);
|
||||||
for (const HBUSHORT *p = &states[state_pos * num_classes]; p < stop; p++)
|
for (const HBUSHORT *p = &states[state_pos * num_classes]; p < stop; p++)
|
||||||
num_entries = hb_max (num_entries, *p + 1);
|
num_entries = hb_max (num_entries, *p + 1u);
|
||||||
state_pos = max_state + 1;
|
state_pos = max_state + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,9 +337,9 @@ struct ContextualSubtable
|
||||||
const EntryData &data = entries[i].data;
|
const EntryData &data = entries[i].data;
|
||||||
|
|
||||||
if (data.markIndex != 0xFFFF)
|
if (data.markIndex != 0xFFFF)
|
||||||
num_lookups = hb_max (num_lookups, 1 + data.markIndex);
|
num_lookups = hb_max (num_lookups, 1u + data.markIndex);
|
||||||
if (data.currentIndex != 0xFFFF)
|
if (data.currentIndex != 0xFFFF)
|
||||||
num_lookups = hb_max (num_lookups, 1 + data.currentIndex);
|
num_lookups = hb_max (num_lookups, 1u + data.currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return_trace (substitutionTables.sanitize (c, this, num_lookups));
|
return_trace (substitutionTables.sanitize (c, this, num_lookups));
|
||||||
|
|
|
@ -83,7 +83,8 @@ static inline constexpr uint16_t hb_uint16_swap (uint16_t v)
|
||||||
static inline constexpr uint32_t hb_uint32_swap (uint32_t v)
|
static inline constexpr uint32_t hb_uint32_swap (uint32_t v)
|
||||||
{ return (hb_uint16_swap (v) << 16) | hb_uint16_swap (v >> 16); }
|
{ return (hb_uint16_swap (v) << 16) | hb_uint16_swap (v >> 16); }
|
||||||
|
|
||||||
template <typename Type, int Bytes = sizeof (Type)> struct BEInt;
|
template <typename Type, int Bytes = sizeof (Type)>
|
||||||
|
struct BEInt;
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
struct BEInt<Type, 1>
|
struct BEInt<Type, 1>
|
||||||
{
|
{
|
||||||
|
@ -124,14 +125,16 @@ struct BEInt<Type, 2>
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
struct BEInt<Type, 3>
|
struct BEInt<Type, 3>
|
||||||
{
|
{
|
||||||
|
static_assert (!hb_is_signed (Type), "");
|
||||||
public:
|
public:
|
||||||
BEInt () = default;
|
BEInt () = default;
|
||||||
constexpr BEInt (Type V) : v {uint8_t ((V >> 16) & 0xFF),
|
constexpr BEInt (Type V) : v {uint8_t ((V >> 16) & 0xFF),
|
||||||
uint8_t ((V >> 8) & 0xFF),
|
uint8_t ((V >> 8) & 0xFF),
|
||||||
uint8_t ((V ) & 0xFF)} {}
|
uint8_t ((V ) & 0xFF)} {}
|
||||||
|
|
||||||
constexpr operator Type () const { return (v[0] << 16)
|
constexpr operator Type () const { return (v[0] << 16)
|
||||||
+ (v[1] << 8)
|
+ (v[1] << 8)
|
||||||
+ (v[2] ); }
|
+ (v[2] ); }
|
||||||
private: uint8_t v[3];
|
private: uint8_t v[3];
|
||||||
};
|
};
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
|
|
|
@ -53,14 +53,19 @@ namespace OT {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Integer types in big-endian order and no alignment requirement */
|
/* Integer types in big-endian order and no alignment requirement */
|
||||||
template <typename Type, unsigned int Size = sizeof (Type)>
|
template <typename Type,
|
||||||
|
unsigned int Size = sizeof (Type)>
|
||||||
struct IntType
|
struct IntType
|
||||||
{
|
{
|
||||||
typedef Type type;
|
typedef Type type;
|
||||||
typedef hb_conditional<hb_is_signed (Type), signed, unsigned> wide_type;
|
|
||||||
|
|
||||||
IntType& operator = (wide_type i) { v = i; return *this; }
|
IntType () = default;
|
||||||
operator wide_type () const { return v; }
|
explicit constexpr IntType (Type V) : v {V} {}
|
||||||
|
IntType& operator = (Type i) { v = i; return *this; }
|
||||||
|
/* For reason we define cast out operator for signed/unsigned, instead of Type, see:
|
||||||
|
* https://github.com/harfbuzz/harfbuzz/pull/2875/commits/09836013995cab2b9f07577a179ad7b024130467 */
|
||||||
|
operator hb_conditional<hb_is_signed (Type), signed, unsigned> () const { return v; }
|
||||||
|
|
||||||
bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; }
|
bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; }
|
||||||
bool operator != (const IntType &o) const { return !(*this == o); }
|
bool operator != (const IntType &o) const { return !(*this == o); }
|
||||||
|
|
||||||
|
|
|
@ -1788,7 +1788,7 @@ struct ClassDefFormat1
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename set_t>
|
template <typename set_t>
|
||||||
bool collect_class (set_t *glyphs, unsigned int klass) const
|
bool collect_class (set_t *glyphs, unsigned klass) const
|
||||||
{
|
{
|
||||||
unsigned int count = classValue.len;
|
unsigned int count = classValue.len;
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
|
@ -1806,7 +1806,7 @@ struct ClassDefFormat1
|
||||||
if (classValue[iter - start]) return true;
|
if (classValue[iter - start]) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const
|
bool intersects_class (const hb_set_t *glyphs, uint16_t klass) const
|
||||||
{
|
{
|
||||||
unsigned int count = classValue.len;
|
unsigned int count = classValue.len;
|
||||||
if (klass == 0)
|
if (klass == 0)
|
||||||
|
@ -1821,8 +1821,7 @@ struct ClassDefFormat1
|
||||||
}
|
}
|
||||||
/* TODO Speed up, using set overlap first? */
|
/* TODO Speed up, using set overlap first? */
|
||||||
/* TODO(iter) Rewrite as dagger. */
|
/* TODO(iter) Rewrite as dagger. */
|
||||||
HBUINT16 k; /* TODO(constexpr) use constructor to initialize. */
|
HBUINT16 k {klass};
|
||||||
k = klass;
|
|
||||||
const HBUINT16 *arr = classValue.arrayZ;
|
const HBUINT16 *arr = classValue.arrayZ;
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (arr[i] == k && glyphs->has (startGlyph + i))
|
if (arr[i] == k && glyphs->has (startGlyph + i))
|
||||||
|
@ -1974,7 +1973,7 @@ struct ClassDefFormat2
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const
|
bool intersects_class (const hb_set_t *glyphs, uint16_t klass) const
|
||||||
{
|
{
|
||||||
unsigned int count = rangeRecord.len;
|
unsigned int count = rangeRecord.len;
|
||||||
if (klass == 0)
|
if (klass == 0)
|
||||||
|
@ -1995,8 +1994,7 @@ struct ClassDefFormat2
|
||||||
}
|
}
|
||||||
/* TODO Speed up, using set overlap first? */
|
/* TODO Speed up, using set overlap first? */
|
||||||
/* TODO(iter) Rewrite as dagger. */
|
/* TODO(iter) Rewrite as dagger. */
|
||||||
HBUINT16 k; /* TODO(constexpr) use constructor to initialize. */
|
HBUINT16 k {klass};
|
||||||
k = klass;
|
|
||||||
const RangeRecord *arr = rangeRecord.arrayZ;
|
const RangeRecord *arr = rangeRecord.arrayZ;
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
if (arr[i].value == k && arr[i].intersects (glyphs))
|
if (arr[i].value == k && arr[i].intersects (glyphs))
|
||||||
|
|
|
@ -2323,12 +2323,7 @@ struct ChainRule
|
||||||
{
|
{
|
||||||
c->copy (len);
|
c->copy (len);
|
||||||
for (const auto g : it)
|
for (const auto g : it)
|
||||||
{
|
c->copy ((HBUINT16) g);
|
||||||
/* TODO(constexpr) Simplify. */
|
|
||||||
HBUINT16 gid;
|
|
||||||
gid = g;
|
|
||||||
c->copy (gid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChainRule* copy (hb_serialize_context_t *c,
|
ChainRule* copy (hb_serialize_context_t *c,
|
||||||
|
|
Loading…
Reference in New Issue