[grilo] core: fix when no slow/writable keys available



commit 923a0a68cf138f2425b8e8f7546b7df31deda61f
Author: Víctor Manuel Jáquez Leal <vjaquez igalia com>
Date:   Thu Oct 21 15:34:29 2010 +0200

    core: fix when no slow/writable keys available
    
    When the source doesn't have slow/writable keys (empty set) the key list is
    not filtered. Also, that code is repeated in each filter type.
    
    This patch set to NULL the filtered key list, and the returned complement is
    the passed key list. The code is isolated in the generic_filter() too.
    
    Finally, added a description of the function.
    
    Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez igalia com>

 src/grl-metadata-source.c |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/src/grl-metadata-source.c b/src/grl-metadata-source.c
index 8395dbf..3d9625d 100644
--- a/src/grl-metadata-source.c
+++ b/src/grl-metadata-source.c
@@ -497,6 +497,15 @@ analyze_keys_to_write (GrlMetadataSource *source,
   return maps;
 }
 
+/**
+ * This method will _intersect two key lists_:
+ *
+ * @keys_to_filter: user provided set we want to filter leaving only the keys that
+ * intersects with the @source_keys set.
+ * @source_keys: the %GrlMetadataSource<!-- -->'s key set
+ * if @return_filtered is %TRUE a copy of the filtered set *complement* will be
+ * returned (a list of the filtered out keys).
+ */
 static GList *
 generic_filter (GrlMetadataSource *source,
                 GList **keys_to_filter,
@@ -509,6 +518,13 @@ generic_filter (GrlMetadataSource *source,
   gboolean got_match;
   GrlKeyID filtered_key;
 
+  if (!source_keys) {
+    if (return_filtered)
+      filtered_keys = *keys_to_filter;
+    *keys_to_filter = NULL;
+    goto end_func;
+  }
+
   iter_source_keys = (GList *) source_keys;
   while (iter_source_keys) {
     got_match = FALSE;
@@ -535,6 +551,7 @@ generic_filter (GrlMetadataSource *source,
     }
   }
 
+end_func:
   return filtered_keys;
 }
 
@@ -794,13 +811,6 @@ grl_metadata_source_filter_slow (GrlMetadataSource *source,
   g_return_val_if_fail (GRL_IS_METADATA_SOURCE (source), NULL);
 
   slow_keys = grl_metadata_source_slow_keys (source);
-  if (!slow_keys) {
-    if (return_filtered) {
-      return g_list_copy (*keys);
-    } else {
-      return NULL;
-    }
-  }
 
   return generic_filter (source, keys, return_filtered, slow_keys);
 }
@@ -831,13 +841,6 @@ grl_metadata_source_filter_writable (GrlMetadataSource *source,
   g_return_val_if_fail (keys != NULL, NULL);
 
   writable_keys = grl_metadata_source_writable_keys (source);
-  if (!writable_keys) {
-    if (return_filtered) {
-      return g_list_copy (*keys);
-    } else {
-      return NULL;
-    }
-  }
 
   return generic_filter (source, keys, return_filtered, writable_keys);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]