platform: refactor nm_dedup_multi_objs_to_ptr_array_head()
by moving the core functionality to "nm-dedup-multi.c". As the ref-counting mechanism now is part of "nm-dedup-multi.c", this works better and is reusable outside of platform.
This commit is contained in:
@@ -931,6 +931,34 @@ nm_dedup_multi_obj_clone (const NMDedupMultiObj *obj)
|
||||
return o;
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
nm_dedup_multi_objs_to_ptr_array_head (const NMDedupMultiHeadEntry *head_entry,
|
||||
NMDedupMultiFcnSelectPredicate predicate,
|
||||
gpointer user_data)
|
||||
{
|
||||
GPtrArray *result;
|
||||
NMDedupMultiIter iter;
|
||||
|
||||
if (!head_entry)
|
||||
return NULL;
|
||||
|
||||
result = g_ptr_array_new_full (head_entry->len,
|
||||
(GDestroyNotify) nm_dedup_multi_obj_unref);
|
||||
nm_dedup_multi_iter_for_each (&iter, head_entry) {
|
||||
const NMDedupMultiObj *obj = iter.current->obj;
|
||||
|
||||
if ( !predicate
|
||||
|| predicate (obj, user_data))
|
||||
g_ptr_array_add (result, (gpointer) nm_dedup_multi_obj_ref (obj));
|
||||
}
|
||||
|
||||
if (result->len == 0) {
|
||||
g_ptr_array_unref (result);
|
||||
return NULL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMDedupMultiIndex *
|
||||
|
@@ -360,6 +360,20 @@ nm_dedup_multi_iter_rewind (NMDedupMultiIter *iter)
|
||||
nm_dedup_multi_iter_init (iter, iter->head);
|
||||
}
|
||||
|
||||
#define nm_dedup_multi_iter_for_each(iter, head_entry) \
|
||||
for (nm_dedup_multi_iter_init ((iter), (head_entry)); \
|
||||
nm_dedup_multi_iter_next ((iter)); \
|
||||
)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef gboolean (*NMDedupMultiFcnSelectPredicate) (/* const NMDedupMultiObj * */ gconstpointer obj,
|
||||
gpointer user_data);
|
||||
|
||||
GPtrArray *nm_dedup_multi_objs_to_ptr_array_head (const NMDedupMultiHeadEntry *head_entry,
|
||||
NMDedupMultiFcnSelectPredicate predicate,
|
||||
gpointer user_data);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NM_DEDUP_MULTI_H__ */
|
||||
|
@@ -2692,29 +2692,9 @@ nm_platform_lookup_clone (NMPlatform *platform,
|
||||
gboolean (*predicate) (const NMPObject *obj, gpointer user_data),
|
||||
gpointer user_data)
|
||||
{
|
||||
const NMDedupMultiHeadEntry *head_entry;
|
||||
GPtrArray *result;
|
||||
NMDedupMultiIter iter;
|
||||
const NMPObject *plobj = NULL;
|
||||
|
||||
head_entry = nm_platform_lookup (platform, lookup);
|
||||
if (!head_entry)
|
||||
return NULL;
|
||||
|
||||
result = g_ptr_array_new_full (head_entry->len,
|
||||
(GDestroyNotify) nmp_object_unref);
|
||||
nmp_cache_iter_for_each (&iter, head_entry, &plobj) {
|
||||
if ( predicate
|
||||
&& !predicate (plobj, user_data))
|
||||
continue;
|
||||
g_ptr_array_add (result, (gpointer) nmp_object_ref (plobj));
|
||||
}
|
||||
|
||||
if (result->len == 0) {
|
||||
g_ptr_array_unref (result);
|
||||
return NULL;
|
||||
}
|
||||
return result;
|
||||
return nm_dedup_multi_objs_to_ptr_array_head (nm_platform_lookup (platform, lookup),
|
||||
(NMDedupMultiFcnSelectPredicate) predicate,
|
||||
user_data);
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user