[PATCH 1/2] fixup! 8e00b48 don't allocate struct wt_status_state dynamically

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

 



From: Matthieu Moy <Matthieu.Moy@xxxxxxx>

The common

void function() {
	struct wt_status_state *state = calloc(...);
	...
	free(state);
}

is essentially a less efficient, and more error prone way of allocating a
variable on the stack (plus, the calloc should have been a xcalloc).
Replace it with an on-stack variable.

While we're there, also replace the individual initializations of fields
with memset(..., 0, ...).

Signed-off-by: Matthieu Moy <Matthieu.Moy@xxxxxxx>
---

(BTW, I didn't find a way to have both --autosquash-compliant and
meaningfull titles)

 wt-status.c | 49 +++++++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index ed28b4f..e65716d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -932,49 +932,42 @@ static void show_bisect_in_progress(struct wt_status *s,
 static void wt_status_print_state(struct wt_status *s)
 {
 	const char *state_color = color(WT_STATUS_IN_PROGRESS, s);
-	struct wt_status_state *state = calloc(1, sizeof(*state));
+	struct wt_status_state state;
 	struct stat st;
 
-	state->merge_in_progress = 0;
-	state->am_in_progress = 0;
-	state->am_empty_patch = 0;
-	state->rebase_in_progress = 0;
-	state->rebase_interactive_in_progress = 0;
-	state->cherry_pick_in_progress = 0;
-	state->bisect_in_progress = 0;
+	memset(&state, 0, sizeof(state));
 
 	if (!stat(git_path("MERGE_HEAD"), &st)) {
-		state->merge_in_progress = 1;
+		state.merge_in_progress = 1;
 	} else if (!stat(git_path("rebase-apply"), &st)) {
 		if (!stat(git_path("rebase-apply/applying"), &st)) {
-			state->am_in_progress = 1;
+			state.am_in_progress = 1;
 			if (!stat(git_path("rebase-apply/patch"), &st) && !st.st_size)
-				state->am_empty_patch = 1;
+				state.am_empty_patch = 1;
 		} else {
-			state->rebase_in_progress = 1;
+			state.rebase_in_progress = 1;
 		}
 	} else if (!stat(git_path("rebase-merge"), &st)) {
 		if (!stat(git_path("rebase-merge/interactive"), &st))
-			state->rebase_interactive_in_progress = 1;
+			state.rebase_interactive_in_progress = 1;
 		else
-			state->rebase_in_progress = 1;
+			state.rebase_in_progress = 1;
 	} else if (!stat(git_path("CHERRY_PICK_HEAD"), &st)) {
-		state->cherry_pick_in_progress = 1;
+		state.cherry_pick_in_progress = 1;
 	}
 	if (!stat(git_path("BISECT_LOG"), &st))
-		state->bisect_in_progress = 1;
-
-	if (state->merge_in_progress)
-		show_merge_in_progress(s, state, state_color);
-	else if (state->am_in_progress)
-		show_am_in_progress(s, state, state_color);
-	else if (state->rebase_in_progress || state->rebase_interactive_in_progress)
-		show_rebase_in_progress(s, state, state_color);
-	else if (state->cherry_pick_in_progress)
-		show_cherry_pick_in_progress(s, state, state_color);
-	if (state->bisect_in_progress)
-		show_bisect_in_progress(s, state, state_color);
-	free(state);
+		state.bisect_in_progress = 1;
+
+	if (state.merge_in_progress)
+		show_merge_in_progress(s, &state, state_color);
+	else if (state.am_in_progress)
+		show_am_in_progress(s, &state, state_color);
+	else if (state.rebase_in_progress || state.rebase_interactive_in_progress)
+		show_rebase_in_progress(s, &state, state_color);
+	else if (state.cherry_pick_in_progress)
+		show_cherry_pick_in_progress(s, &state, state_color);
+	if (state.bisect_in_progress)
+		show_bisect_in_progress(s, &state, state_color);
 }
 
 void wt_status_print(struct wt_status *s)
-- 
1.7.11.rc0.57.g84a04c7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]