git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dylan Reid <dgreid@gmail.com>
To: git@vger.kernel.org
Cc: dgreid@gmail.com
Subject: [PATCH] xdiff: optimise for no whitespace difference when ignoring whitespace.
Date: Mon,  5 Jul 2010 02:06:57 -0400	[thread overview]
Message-ID: <1278310017-24299-1-git-send-email-dgreid@gmail.com> (raw)

Invert the order of the memcmp and flag check are done in xdl_recmatch,
as it makes the common case (there is no whitespace difference) faster.
It costs the case where lines are the same length and contain
whitespace differences, but the common case is more than 20% faster.

Signed-off-by: Dylan Reid <dgreid@gmail.com>
---
 xdiff/xutils.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index bc12f29..dc97a21 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -190,8 +190,10 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
 {
 	int i1, i2;
 
-	if (!(flags & XDF_WHITESPACE_FLAGS))
-		return s1 == s2 && !memcmp(l1, l2, s1);
+	if (s1 == s2 && !memcmp(l1, l2, s1))
+		return 1;
+	else if (!(flags & XDF_WHITESPACE_FLAGS))
+		return 0;
 
 	i1 = 0;
 	i2 = 0;
-- 
1.7.1

             reply	other threads:[~2010-07-05  6:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05  6:06 Dylan Reid [this message]
2010-07-05  8:34 ` [PATCH] xdiff: optimise for no whitespace difference when ignoring whitespace Michael J Gruber
2010-07-05 12:34   ` Dylan Reid
2010-07-05 13:00 ` Dylan Reid
2010-07-06  2:36   ` Junio C Hamano
2010-07-06  3:04     ` Dylan Reid
2010-07-06  3:11 ` Dylan Reid

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

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

  git send-email \
    --in-reply-to=1278310017-24299-1-git-send-email-dgreid@gmail.com \
    --to=dgreid@gmail.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.
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 NNTP newsgroup(s).