git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC][RFC][PATCH 1/2] STRBUF_INIT_CONST: a new way to initialize strbuf

From
René Scharfe <l.s.r@web.de>
Date
Feb 27, 2020, 15:55 UTC
Message-ID
<ef831d8f-7667-3315-ab80-2cb13bb963a1@web.de>
In-Reply-To
<a94a32f6-a650-4ec7-927e-032e22a23ffe@gmail.com>
Am 27.02.20 um 07:50 schrieb Derrick Stolee:
Show 44 quoted lines
> On 2/20/2020 1:49 PM, René Scharfe wrote:
>> Subject: [PATCH] commit-graph: use progress title directly
>>
>> merge_commit_graphs() copies the (translated) progress message into a
>> strbuf and passes the copy to start_delayed_progress() at each loop
>> iteration.  The latter function takes a string pointer, so let's avoid
>> the detour and hand the string to it directly.  That's shorter, simpler
>> and slightly more efficient.
>>
>> Signed-off-by: René Scharfe <l.s.r@web.de>
>> ---
>>  commit-graph.c | 8 ++------
>>  1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/commit-graph.c b/commit-graph.c
>> index 656dd647d5..f013a84e29 100644
>> --- a/commit-graph.c
>> +++ b/commit-graph.c
>> @@ -1657,19 +1657,15 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
>>  {
>>  	struct commit_graph *g = ctx->r->objects->commit_graph;
>>  	uint32_t current_graph_number = ctx->num_commit_graphs_before;
>> -	struct strbuf progress_title = STRBUF_INIT;
>>
>>  	while (g && current_graph_number >= ctx->num_commit_graphs_after) {
>>  		current_graph_number--;
>>
>> -		if (ctx->report_progress) {
>> -			strbuf_addstr(&progress_title, _("Merging commit-graph"));
>> -			ctx->progress = start_delayed_progress(progress_title.buf, 0);
>> -		}
>> +		if (ctx->report_progress)
>> +			ctx->progress = start_delayed_progress(_("Merging commit-graph"), 0);
>>
>>  		merge_commit_graph(ctx, g);
>>  		stop_progress(&ctx->progress);
>> -		strbuf_release(&progress_title);
>>
>>  		g = g->base_graph;
>>  	}
>> --
>
> Not only is this a good change, it no longer leaks memory.
> Thanks!

strbuf_release() frees the allocated memory, so I don't think the code was leaking before. (It would have with strbuf_reset()).

René
Previous: Derrick StoleeNext: Robear Selwans
Message 10 of 11 in “STRBUF_INIT_CONST Cover”
  1. Robear SelwansFeb 18, 2020
  2. [GSoC][RFC][PATCH 1/2] STRBUF_INIT_CONST: a new way to initialize strbufRobear Selwans, Feb 18, 2020
  3. Jeff KingFeb 18, 2020
  4. Robear SelwansFeb 18, 2020
  5. Jeff KingFeb 18, 2020
  6. Johannes SixtFeb 19, 2020
  7. René ScharfeFeb 20, 2020
  8. Robear SelwansFeb 21, 2020
  9. Derrick StoleeFeb 27, 2020
  10. René ScharfeFeb 27, 2020
  11. [GSoC][RFC][PATCH 2/2] STRBUF_INIT_CONST: Adapting strbuf_* functionsRobear Selwans, Feb 18, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.