try_merge_strategy(): use a statically-allocated lock_file object

Even the one lockfile object needn't be allocated each time the function is called. Instead, define one statically-allocated lock_file object and reuse it for every call. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Oct 1, 2014 at 12:28 UTC daccee387a7f3e4ca332649d5311b032a71892e2
1 file changed +7 -7
builtin/merge.c
+7 -7
@@ -656,14 +656,14 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
656 struct commit_list *remoteheads,
657 struct commit *head, const char *head_arg)
658 {
659 - struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
659 + static struct lock_file lock;
660
661 - hold_locked_index(lock, 1);
661 + hold_locked_index(&lock, 1);
662 refresh_cache(REFRESH_QUIET);
663 if (active_cache_changed &&
664 - write_locked_index(&the_index, lock, COMMIT_LOCK))
664 + write_locked_index(&the_index, &lock, COMMIT_LOCK))
665 return error(_("Unable to write index."));
666 - rollback_lock_file(lock);
666 + rollback_lock_file(&lock);
667
668 if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
669 int clean, x;
@@ -695,13 +695,13 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
695 for (j = common; j; j = j->next)
696 commit_list_insert(j->item, &reversed);
697
698 - hold_locked_index(lock, 1);
698 + hold_locked_index(&lock, 1);
699 clean = merge_recursive(&o, head,
700 remoteheads->item, reversed, &result);
701 if (active_cache_changed &&
702 - write_locked_index(&the_index, lock, COMMIT_LOCK))
702 + write_locked_index(&the_index, &lock, COMMIT_LOCK))
703 die (_("unable to write %s"), get_index_file());
704 - rollback_lock_file(lock);
704 + rollback_lock_file(&lock);
705 return clean ? 0 : 1;
706 } else {
707 return try_merge_command(strategy, xopts_nr, xopts,