git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 1/7] commit: simplify fastpath of merge-base computation
Date: Tue, 18 Oct 2016 21:23:39 -0700	[thread overview]
Message-ID: <20161019042345.29766-2-gitster@pobox.com> (raw)
In-Reply-To: <20161019042345.29766-1-gitster@pobox.com>

The get_merge_bases_many*() family of functions first call
merge_bases_many() to find all possible merge bases between a single
commit "one" and a set of other commits "twos[]".  Because this
typically involves traversing the commit graph, which uses the
object flags on the commits involved, the function needs to clear
the flags before it returns.

Except for one special case.  If "one" is exactly one of the "twos",
"one" is the merge base and merge_bases_many() returns a list of
merge bases with a single element, "one", on it, without smudging
the object flags of the commits at all.

We used to use a loop over "twos[]" array to see if this fast-path
would have kicked in in merge_bases_many(), in which case we can
return without cleaning the bits at all.  We can do the same by
inspecting the result in a more direct way, which is conceptually
cleaner.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 commit.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/commit.c b/commit.c
index aada266f9a..6266c0380c 100644
--- a/commit.c
+++ b/commit.c
@@ -955,10 +955,17 @@ static struct commit_list *get_merge_bases_many_0(struct commit *one,
 	int cnt, i;
 
 	result = merge_bases_many(one, n, twos);
-	for (i = 0; i < n; i++) {
-		if (one == twos[i])
-			return result;
-	}
+
+	/*
+	 * The fast-path of 'one' being the merge-base; there is no
+	 * need to clean the object flags in this case.
+	 */
+	if (result && !result->next &&
+	    result->item == one &&
+	    !(one->object.flags & RESULT))
+		return result;
+
+	/* If we didn't get any, or there is only one, we are done */
 	if (!result || !result->next) {
 		if (cleanup) {
 			clear_commit_marks(one, all_flags);
-- 
2.10.1-631-gb2c64dcf30


  reply	other threads:[~2016-10-19  4:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-17 22:28 [RFD] should all merge bases be equal? Junio C Hamano
2016-10-19  4:23 ` [PATCH 0/7] Rejecting useless merge bases Junio C Hamano
2016-10-19  4:23   ` Junio C Hamano [this message]
2016-10-19  4:23   ` [PATCH 2/7] sha1_name: remove ONELINE_SEEN bit Junio C Hamano
2016-10-19  4:23   ` [PATCH 3/7] merge-base: stop moving commits around in remove_redundant() Junio C Hamano
2016-10-19  4:23   ` [PATCH 4/7] merge-base: expose get_merge_bases_many_0() a bit more Junio C Hamano
2016-10-19  4:23   ` [PATCH 5/7] merge-base: mark bases that are on first-parent chain Junio C Hamano
2016-10-19 17:42     ` Junio C Hamano
2016-10-19  4:23   ` [PATCH 6/7] merge-base: limit the output to " Junio C Hamano
2016-10-19  4:23   ` [PATCH 7/7] merge: allow to use only the fp-only merge bases Junio C Hamano
2016-10-19 21:34   ` [PATCH 0/7] Rejecting useless " Junio C Hamano
2017-02-09 14:44 ` [RFD] should all merge bases be equal? Michael Haggerty
2017-02-09 16:57   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161019042345.29766-2-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).