[iter] Use is_sorted_iterator

This commit is contained in:
Behdad Esfahbod 2019-01-07 18:33:04 -05:00
parent ed4336680d
commit 815cde9fa3
9 changed files with 66 additions and 53 deletions

View File

@ -84,7 +84,7 @@ struct hb_aat_map_builder_t
hb_face_t *face;
public:
hb_vector_t<feature_info_t> features;
hb_sorted_vector_t<feature_info_t> features;
};

View File

@ -46,6 +46,8 @@ struct hb_array_t :
*/
hb_array_t () : arrayZ (nullptr), length (0) {}
hb_array_t (Type *array_, unsigned int length_) : arrayZ (array_), length (length_) {}
hb_array_t (const hb_array_t<hb_remove_const (Type)> &o) : arrayZ (o.arrayZ), length (o.length) {}
hb_array_t (const hb_array_t<const Type> &o) : arrayZ (o.arrayZ), length (o.length) {}
template <unsigned int length_> hb_array_t (Type (&array_)[length_]) : arrayZ (array_), length (length_) {}
@ -203,6 +205,8 @@ struct hb_sorted_array_t :
hb_sorted_array_t () : hb_array_t<Type> () {}
hb_sorted_array_t (const hb_array_t<Type> &o) : hb_array_t<Type> (o) {}
hb_sorted_array_t (const hb_sorted_array_t<hb_remove_const (Type)> &o) : hb_array_t<Type> (o) {}
hb_sorted_array_t (const hb_sorted_array_t<const Type> &o) : hb_array_t<Type> (o) {}
hb_sorted_array_t (Type *array_, unsigned int length_) : hb_array_t<Type> (array_, length_) {}
template <unsigned int length_> hb_sorted_array_t (Type (&array_)[length_]) : hb_array_t<Type> (array_) {}

View File

@ -37,15 +37,18 @@
template <typename T> static inline T hb_declval ();
template <typename T> struct hb_remove_const { typedef T value; };
template <typename T> struct hb_remove_const<const T> { typedef T value; };
#define hb_remove_const(T) typename hb_remove_const<T>::value
template <typename T> struct hb_remove_reference { typedef T value; };
template <typename T> struct hb_remove_reference<T &> { typedef T value; };
#define hb_remove_reference(T) typename hb_remove_reference<T>::value
template <typename T> struct hb_remove_pointer { typedef T value; };
template <typename T> struct hb_remove_pointer<T *> { typedef T value; };
#define hb_remove_pointer(T) typename hb_remove_pointer<T>::value
template <typename T> struct hb_match_const { typedef T type; enum { matched = false }; };
template <typename T> struct hb_match_const<const T> { typedef T type; enum { matched = true }; };
#define hb_remove_const(T) typename hb_match_const<T>::type
#define hb_is_const(T) hb_match_const<T>::matched
template <typename T> struct hb_match_reference { typedef T type; enum { matched = false }; };
template <typename T> struct hb_match_reference<T &> { typedef T type; enum { matched = true }; };
#define hb_remove_reference(T) typename hb_match_reference<T>::type
#define hb_is_reference(T) hb_match_reference<T>::matched
template <typename T> struct hb_match_pointer { typedef T type; enum { matched = false }; };
template <typename T> struct hb_match_pointer<T *> { typedef T type; enum { matched = true }; };
#define hb_remove_pointer(T) typename hb_match_pointer<T>::type
#define hb_is_pointer(T) hb_match_pointer<T>::matched
/* Void! For when we need a expression-type of void. */
@ -64,7 +67,7 @@ struct hb_enable_if {};
template<typename T>
struct hb_enable_if<true, T> { typedef T type; };
#define hb_enable_if(Cond) typename hb_enable_if<Cond>::type* = nullptr
#define hb_enable_if(Cond) typename hb_enable_if<(Cond)>::type* = nullptr
#define hb_enable_if_t(Cond, Type) typename hb_enable_if<(Cond), Type>::type

View File

@ -827,7 +827,7 @@ struct CoverageFormat1
}
template <typename Iterator>
hb_enable_if_t (hb_is_iterator (Iterator, const GlyphID),
hb_enable_if_t (hb_is_sorted_iterator (Iterator, const GlyphID),
bool) serialize (hb_serialize_context_t *c,
Iterator glyphs)
{
@ -896,7 +896,7 @@ struct CoverageFormat2
}
template <typename Iterator>
hb_enable_if_t (hb_is_iterator (Iterator, const GlyphID),
hb_enable_if_t (hb_is_sorted_iterator (Iterator, const GlyphID),
bool) serialize (hb_serialize_context_t *c,
Iterator glyphs)
{
@ -1047,7 +1047,7 @@ struct Coverage
}
template <typename Iterator>
hb_enable_if_t (hb_is_iterator (Iterator, const GlyphID),
hb_enable_if_t (hb_is_sorted_iterator (Iterator, const GlyphID),
bool) serialize (hb_serialize_context_t *c,
Iterator glyphs)
{
@ -1240,7 +1240,7 @@ struct ClassDefFormat1
TRACE_SUBSET (this);
const hb_set_t &glyphset = *c->plan->glyphset;
const hb_map_t &glyph_map = *c->plan->glyph_map;
hb_vector_t<GlyphID> glyphs;
hb_sorted_vector_t<GlyphID> glyphs;
hb_vector_t<HBUINT16> klasses;
hb_codepoint_t start = startGlyph;

View File

@ -36,7 +36,7 @@ namespace OT {
static inline void SingleSubst_serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const GlyphID> substitutes);
struct SingleSubstFormat1
@ -92,7 +92,7 @@ struct SingleSubstFormat1
}
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
int delta)
{
TRACE_SERIALIZE (this);
@ -107,7 +107,7 @@ struct SingleSubstFormat1
TRACE_SUBSET (this);
const hb_set_t &glyphset = *c->plan->glyphset;
const hb_map_t &glyph_map = *c->plan->glyph_map;
hb_vector_t<GlyphID> from;
hb_sorted_vector_t<GlyphID> from;
hb_vector_t<GlyphID> to;
hb_codepoint_t delta = deltaGlyphID;
for (/*TODO(C++11)auto*/Coverage::iter_t iter = (this+coverage).iter (); iter; iter++)
@ -189,7 +189,7 @@ struct SingleSubstFormat2
}
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const GlyphID> substitutes)
{
TRACE_SERIALIZE (this);
@ -204,7 +204,7 @@ struct SingleSubstFormat2
TRACE_SUBSET (this);
const hb_set_t &glyphset = *c->plan->glyphset;
const hb_map_t &glyph_map = *c->plan->glyph_map;
hb_vector_t<GlyphID> from;
hb_sorted_vector_t<GlyphID> from;
hb_vector_t<GlyphID> to;
for (/*TODO(C++11)auto*/Coverage::iter_t iter = (this+coverage).iter (); iter; iter++)
{
@ -238,7 +238,7 @@ struct SingleSubstFormat2
struct SingleSubst
{
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const GlyphID> substitutes)
{
TRACE_SERIALIZE (this);
@ -286,7 +286,7 @@ struct SingleSubst
static inline void
SingleSubst_serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const GlyphID> substitutes)
{ c->start_embed<SingleSubst> ()->serialize (c, glyphs, substitutes); }
@ -335,10 +335,10 @@ struct Sequence
}
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs)
hb_array_t<const GlyphID> subst)
{
TRACE_SERIALIZE (this);
return_trace (substitute.serialize (c, glyphs));
return_trace (substitute.serialize (c, subst));
}
bool sanitize (hb_sanitize_context_t *c) const
@ -398,7 +398,7 @@ struct MultipleSubstFormat1
}
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const unsigned int> substitute_len_list,
hb_array_t<const GlyphID> substitute_glyphs_list)
{
@ -444,7 +444,7 @@ struct MultipleSubstFormat1
struct MultipleSubst
{
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const unsigned int> substitute_len_list,
hb_array_t<const GlyphID> substitute_glyphs_list)
{
@ -514,10 +514,10 @@ struct AlternateSet
}
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs)
hb_array_t<const GlyphID> alts)
{
TRACE_SERIALIZE (this);
return_trace (alternates.serialize (c, glyphs));
return_trace (alternates.serialize (c, alts));
}
bool sanitize (hb_sanitize_context_t *c) const
@ -582,7 +582,7 @@ struct AlternateSubstFormat1
}
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const unsigned int> alternate_len_list,
hb_array_t<const GlyphID> alternate_glyphs_list)
{
@ -628,7 +628,7 @@ struct AlternateSubstFormat1
struct AlternateSubst
{
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const unsigned int> alternate_len_list,
hb_array_t<const GlyphID> alternate_glyphs_list)
{
@ -917,7 +917,7 @@ struct LigatureSubstFormat1
}
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> first_glyphs,
hb_sorted_array_t<const GlyphID> first_glyphs,
hb_array_t<const unsigned int> ligature_per_first_glyph_count_list,
hb_array_t<const GlyphID> ligatures_list,
hb_array_t<const unsigned int> component_count_list,
@ -968,7 +968,7 @@ struct LigatureSubstFormat1
struct LigatureSubst
{
bool serialize (hb_serialize_context_t *c,
hb_array_t<const GlyphID> first_glyphs,
hb_sorted_array_t<const GlyphID> first_glyphs,
hb_array_t<const unsigned int> ligature_per_first_glyph_count_list,
hb_array_t<const GlyphID> ligatures_list,
hb_array_t<const unsigned int> component_count_list,
@ -1320,7 +1320,7 @@ struct SubstLookup : Lookup
bool serialize_single (hb_serialize_context_t *c,
uint32_t lookup_props,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const GlyphID> substitutes)
{
TRACE_SERIALIZE (this);
@ -1330,7 +1330,7 @@ struct SubstLookup : Lookup
bool serialize_multiple (hb_serialize_context_t *c,
uint32_t lookup_props,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const unsigned int> substitute_len_list,
hb_array_t<const GlyphID> substitute_glyphs_list)
{
@ -1344,7 +1344,7 @@ struct SubstLookup : Lookup
bool serialize_alternate (hb_serialize_context_t *c,
uint32_t lookup_props,
hb_array_t<const GlyphID> glyphs,
hb_sorted_array_t<const GlyphID> glyphs,
hb_array_t<const unsigned int> alternate_len_list,
hb_array_t<const GlyphID> alternate_glyphs_list)
{
@ -1358,7 +1358,7 @@ struct SubstLookup : Lookup
bool serialize_ligature (hb_serialize_context_t *c,
uint32_t lookup_props,
hb_array_t<const GlyphID> first_glyphs,
hb_sorted_array_t<const GlyphID> first_glyphs,
hb_array_t<const unsigned int> ligature_per_first_glyph_count_list,
hb_array_t<const GlyphID> ligatures_list,
hb_array_t<const unsigned int> component_count_list,

View File

@ -167,7 +167,7 @@ struct hb_ot_map_t
hb_mask_t global_mask;
hb_vector_t<feature_map_t> features;
hb_sorted_vector_t<feature_map_t> features;
hb_vector_t<lookup_map_t> lookups[2]; /* GSUB/GPOS */
hb_vector_t<stage_map_t> stages[2]; /* GSUB/GPOS */
};

View File

@ -88,7 +88,7 @@ arabic_fallback_synthesize_lookup_single (const hb_ot_shape_plan_t *plan HB_UNUS
OT::SubstLookup *lookup = c.start_serialize<OT::SubstLookup> ();
bool ret = lookup->serialize_single (&c,
OT::LookupFlag::IgnoreMarks,
hb_array (glyphs, num_glyphs),
hb_sorted_array (glyphs, num_glyphs),
hb_array (substitutes, num_glyphs));
c.end_serialize ();
/* TODO sanitize the results? */
@ -163,7 +163,7 @@ arabic_fallback_synthesize_lookup_ligature (const hb_ot_shape_plan_t *plan HB_UN
OT::SubstLookup *lookup = c.start_serialize<OT::SubstLookup> ();
bool ret = lookup->serialize_ligature (&c,
OT::LookupFlag::IgnoreMarks,
hb_array (first_glyphs, num_first_glyphs),
hb_sorted_array (first_glyphs, num_first_glyphs),
hb_array (ligature_per_first_glyph_count_list, num_first_glyphs),
hb_array (ligature_list, num_ligatures),
hb_array (component_count_list, num_ligatures),

View File

@ -186,7 +186,7 @@ struct hb_set_t
hb_object_header_t header;
bool successful; /* Allocations successful */
mutable unsigned int population;
hb_vector_t<page_map_t> page_map;
hb_sorted_vector_t<page_map_t> page_map;
hb_vector_t<page_t> pages;
void init_shallow ()

View File

@ -115,15 +115,6 @@ struct hb_vector_t
hb_sorted_array_t<const Type> as_sorted_array () const
{ return hb_sorted_array (arrayZ(), length); }
hb_array_t<const Type> sorted_sub_array (unsigned int start_offset, unsigned int count) const
{ return as_sorted_array ().sorted_sub_array (start_offset, count);}
hb_array_t<const Type> sorted_sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */) const
{ return as_sorted_array ().sorted_sub_array (start_offset, count);}
hb_array_t<Type> sorted_sub_array (unsigned int start_offset, unsigned int count)
{ return as_sorted_array ().sorted_sub_array (start_offset, count);}
hb_array_t<Type> sorted_sub_array (unsigned int start_offset, unsigned int *count = nullptr /* IN/OUT */)
{ return as_sorted_array ().sorted_sub_array (start_offset, count);}
template <typename T> explicit_operator T * () { return arrayZ(); }
template <typename T> explicit_operator const T * () const { return arrayZ(); }
@ -247,19 +238,34 @@ struct hb_vector_t
template <typename T>
const Type *lsearch (const T &x, const Type *not_found = nullptr) const
{ return as_array ().lsearch (x, not_found); }
};
template <typename Type>
struct hb_sorted_vector_t : hb_vector_t<Type>
{
hb_sorted_array_t< Type> as_array () { return hb_sorted_array (this->arrayZ(), this->length); }
hb_sorted_array_t<const Type> as_array () const { return hb_sorted_array (this->arrayZ(), this->length); }
/* Iterator. */
typedef hb_sorted_array_t<const Type> const_iter_t;
typedef hb_sorted_array_t< Type> iter_t;
const_iter_t iter () const { return as_array (); }
const_iter_t citer () const { return as_array (); }
iter_t iter () { return as_array (); }
operator iter_t () { return iter (); }
operator const_iter_t () const { return iter (); }
template <typename T>
Type *bsearch (const T &x, Type *not_found = nullptr)
{ return as_sorted_array ().bsearch (x, not_found); }
{ return as_array ().bsearch (x, not_found); }
template <typename T>
const Type *bsearch (const T &x, const Type *not_found = nullptr) const
{ return as_sorted_array ().bsearch (x, not_found); }
{ return as_array ().bsearch (x, not_found); }
template <typename T>
bool bfind (const T &x, unsigned int *i = nullptr,
hb_bfind_not_found_t not_found = HB_BFIND_NOT_FOUND_DONT_STORE,
unsigned int to_store = (unsigned int) -1) const
{ return as_sorted_array ().bfind (x, i, not_found, to_store); }
{ return as_array ().bfind (x, i, not_found, to_store); }
};
#endif /* HB_VECTOR_HH */