diff --git a/src/hb-iter.hh b/src/hb-iter.hh index 775fba46f..48cc68738 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -75,6 +75,7 @@ struct hb_iter_t void prev () { thiz()->__prev__ (); } void rewind (unsigned n) { thiz()->__rewind__ (n); } unsigned len () const { return thiz()->__len__ (); } + bool random_access () const { return thiz()->__random_access__ (); } /* * Subclasses overrides: @@ -99,6 +100,9 @@ struct hb_iter_t /* Population: Implement __len__() if known. */ unsigned __len__ () const { iter_t c (*thiz()); unsigned l = 0; while (c) { c++; l++; }; return l; } + + /* Random access: Return true if len(), forward(), item_at() are fast. */ + bool __random_access__ () const { return false; } }; diff --git a/src/test-iter.cc b/src/test-iter.cc index 32fb9f831..f54bf0ae3 100644 --- a/src/test-iter.cc +++ b/src/test-iter.cc @@ -39,6 +39,7 @@ struct array_iter_t : hb_iter_t, T> void __forward__ (unsigned n) { arr += n; } void __rewind__ (unsigned n) { arr -= n; } unsigned __len__ () const { return arr.len; } + bool __random_access__ () const { return true; } private: hb_array_t arr;