From 3dbe1e364c19d82ab436b9ea7b41c9754d43e923 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 21 Dec 2018 15:53:09 -0500 Subject: [PATCH] [iter] Add .random_access() --- src/hb-iter.hh | 4 ++++ src/test-iter.cc | 1 + 2 files changed, 5 insertions(+) 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;