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

In xdl_recmatch, do the memcmp to check if the two lines are equal before
checking if whitespace flags are set.  If the lines are identicle, then
there is no need to check if they differ only in whitespace.
This 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 |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index bc12f29..22f9bd6 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 (s1 == s2 && !memcmp(l1, l2, s1))
+		return 1;
 	if (!(flags & XDF_WHITESPACE_FLAGS))
-		return s1 == s2 && !memcmp(l1, l2, s1);
+		return 0;
 
 	i1 = 0;
 	i2 = 0;
-- 
1.7.1

  parent reply	other threads:[~2010-07-05 12:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05  6:06 [PATCH] xdiff: optimise for no whitespace difference when ignoring whitespace Dylan Reid
2010-07-05  8:34 ` Michael J Gruber
2010-07-05 12:34   ` Dylan Reid
2010-07-05 13:00 ` Dylan Reid [this message]
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=1278334842-9701-1-git-send-email-dgreid@gmail.com \
    --to=dgreid@gmail.com \
    --cc=git@drmicha.warpmail.net \
    --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).