lib/prune: Avoid unnecessary object serialization
authorDan Nicholson <dbn@endlessos.org>
Thu, 18 Nov 2021 17:59:46 +0000 (10:59 -0700)
committerDan Nicholson <dbn@endlessos.org>
Thu, 18 Nov 2021 18:04:06 +0000 (11:04 -0700)
`repo_prune_internal` was deserializing each object and passing the
components to `maybe_prune_loose_object`, which promptly reserialized
it.

src/libostree/ostree-repo-prune.c

index c4ce64abca3fefc1a50df0023f32fb10ea22e390..82fcf639b1fd5af980f47090b7dcd47ed52b0fca 100644 (file)
@@ -39,17 +39,17 @@ typedef struct {
 } OtPruneData;
 
 static gboolean
-maybe_prune_loose_object (OtPruneData        *data,
-                          OstreeRepoPruneFlags    flags,
-                          const char         *checksum,
-                          OstreeObjectType    objtype,
-                          GCancellable       *cancellable,
-                          GError            **error)
+maybe_prune_loose_object (OtPruneData           *data,
+                          OstreeRepoPruneFlags   flags,
+                          GVariant              *key,
+                          GCancellable          *cancellable,
+                          GError               **error)
 {
   gboolean reachable = FALSE;
-  g_autoptr(GVariant) key = NULL;
+  const char *checksum;
+  OstreeObjectType objtype;
 
-  key = ostree_object_name_serialize (checksum, objtype);
+  ostree_object_name_deserialize (key, &checksum, &objtype);
 
   if (g_hash_table_lookup_extended (data->reachable, key, NULL, NULL))
     reachable = TRUE;
@@ -276,17 +276,14 @@ repo_prune_internal (OstreeRepo        *self,
 
   GLNX_HASH_TABLE_FOREACH_KV (objects, GVariant*, serialized_key, GVariant*, objdata)
     {
-      const char *checksum;
-      OstreeObjectType objtype;
       gboolean is_loose;
 
-      ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
       g_variant_get_child (objdata, 0, "b", &is_loose);
 
       if (!is_loose)
         continue;
 
-      if (!maybe_prune_loose_object (&data, options->flags, checksum, objtype,
+      if (!maybe_prune_loose_object (&data, options->flags, serialized_key,
                                      cancellable, error))
         return FALSE;
     }