Re: [PATCH v2 5/8] grep: allocate subrepos on heap

2 messages, 2 authors, 2021-08-16 · open the first message on its own page

Re: [PATCH v2 5/8] grep: allocate subrepos on heap

From: Junio C Hamano <hidden>
Date: 2021-08-13 21:45:03

Jonathan Tan [off-list ref] writes:
+static void free_repos(void)
+{
+	int i;
+
+	for (i = 0; i < repos_to_free_nr; i++) {
+		repo_clear(repos_to_free[i]);
+		free(repos_to_free[i]);
+	}
+	free(repos_to_free);
+	repos_to_free_nr = 0;
+	repos_to_free_alloc = 0;
The clearing of nr/alloc is new in this round.

It does not matter if we won't using anything that allocates
repositories and accumulates them in repos_to_free after we call
free_repos() once, but then clearing the nr/alloc would not matter,
either, so it may be more consistent to FREE_AND_NULL(repos_to_free)
here, not just free(), to prepare for another call to ALLOC_GROW()
on the <repos_to_free, repos_to_free_nr, repos_to_free_alloc> tuple,
which eventually will call into REALLOC_ARRAY() on the pointer, I
would think.

Re: [PATCH v2 5/8] grep: allocate subrepos on heap

From: Jonathan Tan <hidden>
Date: 2021-08-16 19:43:03

Jonathan Tan [off-list ref] writes:
quoted
+static void free_repos(void)
+{
+	int i;
+
+	for (i = 0; i < repos_to_free_nr; i++) {
+		repo_clear(repos_to_free[i]);
+		free(repos_to_free[i]);
+	}
+	free(repos_to_free);
+	repos_to_free_nr = 0;
+	repos_to_free_alloc = 0;
The clearing of nr/alloc is new in this round.

It does not matter if we won't using anything that allocates
repositories and accumulates them in repos_to_free after we call
free_repos() once, but then clearing the nr/alloc would not matter,
either, so it may be more consistent to FREE_AND_NULL(repos_to_free)
here, not just free(), to prepare for another call to ALLOC_GROW()
on the <repos_to_free, repos_to_free_nr, repos_to_free_alloc> tuple,
which eventually will call into REALLOC_ARRAY() on the pointer, I
would think.
Yes, FREE_AND_NULL is more consistent. I'll change it.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help