From 478a42536ff7ab777a7774fbfdb9c5e51334a14e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 5 May 2011 12:39:51 -0400 Subject: [PATCH] Make array/map implementation more generic --- src/hb-object-private.hh | 2 ++ src/hb-private.hh | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hb-object-private.hh b/src/hb-object-private.hh index 1f49885..77e0089 100644 --- a/src/hb-object-private.hh +++ b/src/hb-object-private.hh @@ -125,6 +125,8 @@ struct hb_user_data_array_t { map.unset (key); return true; } + if (!key) + return false; hb_user_data_t user_data = {data, destroy}; return map.set (key, user_data); } diff --git a/src/hb-private.hh b/src/hb-private.hh index 1d40d66..9a23cd3 100644 --- a/src/hb-private.hh +++ b/src/hb-private.hh @@ -300,20 +300,20 @@ struct hb_map_t private: - inline item_t *find (Key key) { - if (unlikely (!key)) return NULL; + template + inline item_t *find (T key) { for (unsigned int i = 0; i < items.len; i++) - if (key == items[i].key) + if (items[i].key == key) return &items[i]; return NULL; } public: - inline bool set (Key key, + template + inline bool set (T key, Value &value) { - if (unlikely (!key)) return NULL; item_t *item; item = find (key); if (item) @@ -337,7 +337,8 @@ struct hb_map_t items.pop (); } - inline Value *get (Key key) + template + inline Value *get (T key) { item_t *item = find (key); return item ? &item->value : NULL; -- 2.7.4