Use new hb_auto_t<> constructor with Coverage::Iter

This commit is contained in:
Behdad Esfahbod 2018-08-25 21:15:39 -07:00
parent ddea4d19cf
commit acce1fa3ea
2 changed files with 52 additions and 43 deletions

View File

@ -743,6 +743,7 @@ struct CoverageFormat1
/* Older compilers need this to be public. */
struct Iter {
inline void init (const struct CoverageFormat1 &c_) { c = &c_; i = 0; };
inline void fini (void) {};
inline bool more (void) { return i < c->glyphArray.len; }
inline void next (void) { i++; }
inline hb_codepoint_t get_glyph (void) { return c->glyphArray[i]; }
@ -859,6 +860,7 @@ struct CoverageFormat2
i = c->rangeRecord.len;
}
}
inline void fini (void) {};
inline bool more (void) { return i < c->rangeRecord.len; }
inline void next (void)
{
@ -924,7 +926,8 @@ struct Coverage
if (glyphs[i - 1] + 1 != glyphs[i])
num_ranges++;
u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2);
switch (u.format) {
switch (u.format)
{
case 1: return_trace (u.format1.serialize (c, glyphs, num_glyphs));
case 2: return_trace (u.format2.serialize (c, glyphs, num_glyphs));
default:return_trace (false);
@ -935,25 +938,27 @@ struct Coverage
{
TRACE_SANITIZE (this);
if (!u.format.sanitize (c)) return_trace (false);
switch (u.format) {
switch (u.format)
{
case 1: return_trace (u.format1.sanitize (c));
case 2: return_trace (u.format2.sanitize (c));
default:return_trace (true);
}
}
inline bool intersects (const hb_set_t *glyphs) const {
inline bool intersects (const hb_set_t *glyphs) const
{
/* TODO speed this up */
Coverage::Iter iter;
for (iter.init (*this); iter.more (); iter.next ()) {
for (hb_auto_t<Coverage::Iter> iter (*this); iter.more (); iter.next ())
if (glyphs->has (iter.get_glyph ()))
return true;
}
return false;
}
inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const {
switch (u.format) {
inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
{
switch (u.format)
{
case 1: return u.format1.intersects_coverage (glyphs, index);
case 2: return u.format2.intersects_coverage (glyphs, index);
default:return false;
@ -963,47 +968,61 @@ struct Coverage
/* Might return false if array looks unsorted.
* Used for faster rejection of corrupt data. */
template <typename set_t>
inline bool add_coverage (set_t *glyphs) const {
switch (u.format) {
inline bool add_coverage (set_t *glyphs) const
{
switch (u.format)
{
case 1: return u.format1.add_coverage (glyphs);
case 2: return u.format2.add_coverage (glyphs);
default:return false;
}
}
struct Iter {
struct Iter
{
Iter (void) : format (0), u () {};
inline void init (const Coverage &c_) {
inline void init (const Coverage &c_)
{
format = c_.u.format;
switch (format) {
switch (format)
{
case 1: u.format1.init (c_.u.format1); return;
case 2: u.format2.init (c_.u.format2); return;
default: return;
default: return;
}
}
inline bool more (void) {
switch (format) {
inline void fini (void) {}
inline bool more (void)
{
switch (format)
{
case 1: return u.format1.more ();
case 2: return u.format2.more ();
default:return false;
}
}
inline void next (void) {
switch (format) {
inline void next (void)
{
switch (format)
{
case 1: u.format1.next (); break;
case 2: u.format2.next (); break;
default: break;
default: break;
}
}
inline hb_codepoint_t get_glyph (void) {
switch (format) {
inline hb_codepoint_t get_glyph (void)
{
switch (format)
{
case 1: return u.format1.get_glyph ();
case 2: return u.format2.get_glyph ();
default:return 0;
}
}
inline unsigned int get_coverage (void) {
switch (format) {
inline unsigned int get_coverage (void)
{
switch (format)
{
case 1: return u.format1.get_coverage ();
case 2: return u.format2.get_coverage ();
default:return -1;

View File

@ -40,8 +40,7 @@ struct SingleSubstFormat1
inline void closure (hb_closure_context_t *c) const
{
TRACE_CLOSURE (this);
Coverage::Iter iter;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
/* TODO Switch to range-based API to work around malicious fonts.
* https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -55,8 +54,7 @@ struct SingleSubstFormat1
{
TRACE_COLLECT_GLYPHS (this);
if (unlikely (!(this+coverage).add_coverage (c->input))) return;
Coverage::Iter iter;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
/* TODO Switch to range-based API to work around malicious fonts.
* https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -125,9 +123,8 @@ struct SingleSubstFormat2
inline void closure (hb_closure_context_t *c) const
{
TRACE_CLOSURE (this);
Coverage::Iter iter;
unsigned int count = substitute.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -140,9 +137,8 @@ struct SingleSubstFormat2
{
TRACE_COLLECT_GLYPHS (this);
if (unlikely (!(this+coverage).add_coverage (c->input))) return;
Coverage::Iter iter;
unsigned int count = substitute.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -332,9 +328,8 @@ struct MultipleSubstFormat1
inline void closure (hb_closure_context_t *c) const
{
TRACE_CLOSURE (this);
Coverage::Iter iter;
unsigned int count = sequence.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -454,9 +449,8 @@ struct AlternateSubstFormat1
inline void closure (hb_closure_context_t *c) const
{
TRACE_CLOSURE (this);
Coverage::Iter iter;
unsigned int count = alternateSet.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -473,9 +467,8 @@ struct AlternateSubstFormat1
{
TRACE_COLLECT_GLYPHS (this);
if (unlikely (!(this+coverage).add_coverage (c->input))) return;
Coverage::Iter iter;
unsigned int count = alternateSet.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -781,9 +774,8 @@ struct LigatureSubstFormat1
inline void closure (hb_closure_context_t *c) const
{
TRACE_CLOSURE (this);
Coverage::Iter iter;
unsigned int count = ligatureSet.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -796,9 +788,8 @@ struct LigatureSubstFormat1
{
TRACE_COLLECT_GLYPHS (this);
if (unlikely (!(this+coverage).add_coverage (c->input))) return;
Coverage::Iter iter;
unsigned int count = ligatureSet.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
@ -950,9 +941,8 @@ struct ReverseChainSingleSubstFormat1
return;
const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
Coverage::Iter iter;
count = substitute.len;
for (iter.init (this+coverage); iter.more (); iter.next ())
for (hb_auto_t<Coverage::Iter> iter (this+coverage); iter.more (); iter.next ())
{
if (unlikely (iter.get_coverage () >= count))
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */