[set] Cache length in iterator
This commit is contained in:
parent
d0a706c7fd
commit
f88fed5cd8
|
@ -673,17 +673,20 @@ struct hb_set_t
|
||||||
*/
|
*/
|
||||||
struct iter_t : hb_sorted_iter_t<iter_t, hb_codepoint_t>
|
struct iter_t : hb_sorted_iter_t<iter_t, hb_codepoint_t>
|
||||||
{
|
{
|
||||||
iter_t (const hb_set_t &s_) : s (s_), v (INVALID) { __next__ (); }
|
iter_t (const hb_set_t &s_) :
|
||||||
|
s (s_), v (INVALID), l (s.get_population () + 1) { __next__ (); }
|
||||||
|
|
||||||
typedef hb_codepoint_t __item_type__;
|
typedef hb_codepoint_t __item_type__;
|
||||||
hb_codepoint_t __item__ () const { return v; }
|
hb_codepoint_t __item__ () const { return v; }
|
||||||
bool __more__ () const { return v != INVALID; }
|
bool __more__ () const { return v != INVALID; }
|
||||||
void __next__ () { s.next (&v); }
|
void __next__ () { s.next (&v); if (l) l--; }
|
||||||
void __prev__ () { s.previous (&v); }
|
void __prev__ () { s.previous (&v); }
|
||||||
|
unsigned __len__ () { return l; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const hb_set_t &s;
|
const hb_set_t &s;
|
||||||
hb_codepoint_t v;
|
hb_codepoint_t v;
|
||||||
|
unsigned l;
|
||||||
};
|
};
|
||||||
iter_t iter () { return iter_t (*this); }
|
iter_t iter () { return iter_t (*this); }
|
||||||
operator iter_t () { return iter (); }
|
operator iter_t () { return iter (); }
|
||||||
|
|
Loading…
Reference in New Issue