提交 478a4253 编写于 作者: B Behdad Esfahbod

Make array/map implementation more generic

上级 b81bd429
...@@ -125,6 +125,8 @@ struct hb_user_data_array_t { ...@@ -125,6 +125,8 @@ struct hb_user_data_array_t {
map.unset (key); map.unset (key);
return true; return true;
} }
if (!key)
return false;
hb_user_data_t user_data = {data, destroy}; hb_user_data_t user_data = {data, destroy};
return map.set (key, user_data); return map.set (key, user_data);
} }
......
...@@ -300,20 +300,20 @@ struct hb_map_t ...@@ -300,20 +300,20 @@ struct hb_map_t
private: private:
inline item_t *find (Key key) { template <typename T>
if (unlikely (!key)) return NULL; inline item_t *find (T key) {
for (unsigned int i = 0; i < items.len; i++) for (unsigned int i = 0; i < items.len; i++)
if (key == items[i].key) if (items[i].key == key)
return &items[i]; return &items[i];
return NULL; return NULL;
} }
public: public:
inline bool set (Key key, template <typename T>
inline bool set (T key,
Value &value) Value &value)
{ {
if (unlikely (!key)) return NULL;
item_t *item; item_t *item;
item = find (key); item = find (key);
if (item) if (item)
...@@ -337,7 +337,8 @@ struct hb_map_t ...@@ -337,7 +337,8 @@ struct hb_map_t
items.pop (); items.pop ();
} }
inline Value *get (Key key) template <typename T>
inline Value *get (T key)
{ {
item_t *item = find (key); item_t *item = find (key);
return item ? &item->value : NULL; return item ? &item->value : NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册