[gnome-builder/wip/chergert/buildcleanup: 3/10] subprocess: simplify replace_argv



commit 4ba0cd3270e2e7e705345abd21aa524ae68f91f1
Author: Christian Hergert <chergert redhat com>
Date:   Sun Dec 11 19:13:42 2016 -0800

    subprocess: simplify replace_argv
    
    We can simplify this by overwriting the previous item and then freeing
    the old string.

 libide/subprocess/ide-subprocess-launcher.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/libide/subprocess/ide-subprocess-launcher.c b/libide/subprocess/ide-subprocess-launcher.c
index 7f04cf6..154b9c8 100644
--- a/libide/subprocess/ide-subprocess-launcher.c
+++ b/libide/subprocess/ide-subprocess-launcher.c
@@ -840,11 +840,15 @@ ide_subprocess_launcher_replace_argv (IdeSubprocessLauncher *self,
                                       const gchar           *arg)
 {
   IdeSubprocessLauncherPrivate *priv = ide_subprocess_launcher_get_instance_private (self);
+  gchar *old_arg;
 
   g_return_if_fail (IDE_IS_SUBPROCESS_LAUNCHER (self));
-  g_return_if_fail (index < priv->argv->len);
+  g_return_if_fail (priv->argv->len > 0);
+  g_return_if_fail (index < (priv->argv->len - 1));
   g_return_if_fail (arg != NULL);
 
-  g_ptr_array_remove_index (priv->argv, index);
-  g_ptr_array_insert (priv->argv, (index == priv->argv->len ? -1 : index), g_strdup (arg));
+  /* overwriting in place */
+  old_arg = g_ptr_array_index (priv->argv, index);
+  g_ptr_array_index (priv->argv, index) = g_strdup (arg);
+  g_free (old_arg);
 }


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