From 13a8786c7c580651d8a6db9345b9aa85ca8ed956 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 11 Sep 2018 01:07:06 +0200 Subject: [PATCH] Add (unused) hb_array_t<> --- src/hb-dsalgs.hh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index 7e06ff1..def968e 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -29,6 +29,8 @@ #include "hb.hh" +#include "hb-null.hh" + /* Void! For when we need a expression-type of void. */ typedef const struct _hb_void_t *hb_void_t; @@ -507,6 +509,24 @@ struct hb_auto_t : Type void fini (void) {} }; +template +struct hb_array_t +{ + inline hb_array_t (void) : arrayZ (nullptr), len (0) {} + inline hb_array_t (const T *array_, unsigned int len_) : arrayZ (array_), len (len_) {} + + inline const T& operator [] (unsigned int i) const + { + if (unlikely (i >= len)) return Null(T); + return arrayZ[i]; + } + + inline void free (void) { ::free ((void *) arrayZ); arrayZ = nullptr; len = 0; } + + const T *arrayZ; + unsigned int len; +}; + struct hb_bytes_t { inline hb_bytes_t (void) : bytes (nullptr), len (0) {} -- 2.7.4