diff src/sound.c @ 31809:543153d582d5 v9.0.1237

patch 9.0.1237: code is indented more than necessary Commit: https://github.com/vim/vim/commit/6ec66660476562e643deceb7c325cd0e8c903663 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Jan 23 20:46:21 2023 +0000 patch 9.0.1237: code is indented more than necessary Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes #11858)
author Bram Moolenaar <Bram@vim.org>
date Mon, 23 Jan 2023 22:00:04 +0100
parents 12c0e0f13585
children 4545f58c8490
line wrap: on
line diff
--- a/src/sound.c
+++ b/src/sound.c
@@ -54,15 +54,16 @@ get_sound_callback(typval_T *arg)
 
     soundcb = ALLOC_ONE(soundcb_T);
     if (soundcb == NULL)
+    {
 	free_callback(&callback);
-    else
-    {
-	soundcb->snd_next = first_callback;
-	first_callback = soundcb;
-	set_callback(&soundcb->snd_callback, &callback);
-	if (callback.cb_free_name)
-	    vim_free(callback.cb_name);
+	return NULL;
     }
+
+    soundcb->snd_next = first_callback;
+    first_callback = soundcb;
+    set_callback(&soundcb->snd_callback, &callback);
+    if (callback.cb_free_name)
+	vim_free(callback.cb_name);
     return soundcb;
 }
 
@@ -195,45 +196,45 @@ sound_play_common(typval_T *argvars, typ
 
     if (context == NULL)
 	ca_context_create(&context);
-    if (context != NULL)
-    {
-	soundcb_T	*soundcb = get_sound_callback(&argvars[1]);
-	int		res = CA_ERROR_INVALID;
+    if (context == NULL)
+	return;
+
+    soundcb_T	*soundcb = get_sound_callback(&argvars[1]);
+    int		res = CA_ERROR_INVALID;
 
-	++sound_id;
-	if (soundcb == NULL)
-	{
-	    res = ca_context_play(context, sound_id,
-		    playfile ? CA_PROP_MEDIA_FILENAME : CA_PROP_EVENT_ID,
-						    tv_get_string(&argvars[0]),
-		    CA_PROP_CANBERRA_CACHE_CONTROL, "volatile",
-		    NULL);
-	}
-	else
-	{
-	    static ca_proplist *proplist = NULL;
+    ++sound_id;
+    if (soundcb == NULL)
+    {
+	res = ca_context_play(context, sound_id,
+		playfile ? CA_PROP_MEDIA_FILENAME : CA_PROP_EVENT_ID,
+		tv_get_string(&argvars[0]),
+		CA_PROP_CANBERRA_CACHE_CONTROL, "volatile",
+		NULL);
+    }
+    else
+    {
+	static ca_proplist *proplist = NULL;
 
-	    ca_proplist_create(&proplist);
-	    if (proplist != NULL)
-	    {
-		if (playfile)
-		    ca_proplist_sets(proplist, CA_PROP_MEDIA_FILENAME,
-					   (char *)tv_get_string(&argvars[0]));
-		else
-		    ca_proplist_sets(proplist, CA_PROP_EVENT_ID,
-					   (char *)tv_get_string(&argvars[0]));
-		ca_proplist_sets(proplist, CA_PROP_CANBERRA_CACHE_CONTROL,
-			"volatile");
-		res = ca_context_play_full(context, sound_id, proplist,
-						      sound_callback, soundcb);
-		if (res != CA_SUCCESS)
-		    delete_sound_callback(soundcb);
+	ca_proplist_create(&proplist);
+	if (proplist != NULL)
+	{
+	    if (playfile)
+		ca_proplist_sets(proplist, CA_PROP_MEDIA_FILENAME,
+			(char *)tv_get_string(&argvars[0]));
+	    else
+		ca_proplist_sets(proplist, CA_PROP_EVENT_ID,
+			(char *)tv_get_string(&argvars[0]));
+	    ca_proplist_sets(proplist, CA_PROP_CANBERRA_CACHE_CONTROL,
+		    "volatile");
+	    res = ca_context_play_full(context, sound_id, proplist,
+		    sound_callback, soundcb);
+	    if (res != CA_SUCCESS)
+		delete_sound_callback(soundcb);
 
-		ca_proplist_destroy(proplist);
-	    }
+	    ca_proplist_destroy(proplist);
 	}
-	rettv->vval.v_number = res == CA_SUCCESS ? sound_id : 0;
     }
+    rettv->vval.v_number = res == CA_SUCCESS ? sound_id : 0;
 }
 
     void
@@ -270,11 +271,10 @@ f_sound_stop(typval_T *argvars, typval_T
     void
 f_sound_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
 {
-    if (context != NULL)
-    {
-	ca_context_destroy(context);
-	context = NULL;
-    }
+    if (context == NULL)
+	return;
+    ca_context_destroy(context);
+    context = NULL;
 }
 
 # if defined(EXITFREE) || defined(PROTO)