[PATCH 2/5] diffcore-rename: avoid unnecessary strdup'ing in break_idx
- From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
- Date
- May 27, 2021, 08:37 UTC
- Message-ID
- <7212816c8d4734b33a874835e53d9e13b3198971.1622104642.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.962.git.1622104642.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
The keys of break_idx are strings from the diff_filepairs of diff_queued_diff. break_idx is only used in location_rename_dst(), and that usage is always before any free'ing of the pairs (and thus the strings in the pairs). As such, there is no need to strdup these keys; we can just reuse the existing strings as-is.
The merge logic doesn't make use of break detection, so this does not affect the performance of any of my testcases. It was just a minor unrelated optimization noted in passing while looking at the code.
Signed-off-by: Elijah Newren <newren@gmail.com> --- diffcore-rename.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c index 3375e24659ea..e333a6d64791 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -54,7 +54,7 @@ static void register_rename_src(struct diff_filepair *p) if (p->broken_pair) { if (!break_idx) { break_idx = xmalloc(sizeof(*break_idx)); - strintmap_init(break_idx, -1); + strintmap_init_with_options(break_idx, -1, NULL, 0); } strintmap_set(break_idx, p->one->path, rename_dst_nr); }
-- gitgitgadget