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

Make array/map implementation more generic

上级 b81bd429
......@@ -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);
}
......
......@@ -300,20 +300,20 @@ struct hb_map_t
private:
inline item_t *find (Key key) {
if (unlikely (!key)) return NULL;
template <typename T>
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 <typename T>
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 <typename T>
inline Value *get (T key)
{
item_t *item = find (key);
return item ? &item->value : NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册