Skip to content

Commit b4cf0f1

Browse files
dgreidgitster
authored andcommitted
xdiff: optimise for no whitespace difference when ignoring whitespace.
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 identical, 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6b09778 commit b4cf0f1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

xdiff/xutils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
190190
{
191191
int i1, i2;
192192

193+
if (s1 == s2 && !memcmp(l1, l2, s1))
194+
return 1;
193195
if (!(flags & XDF_WHITESPACE_FLAGS))
194-
return s1 == s2 && !memcmp(l1, l2, s1);
196+
return 0;
195197

196198
i1 = 0;
197199
i2 = 0;

0 commit comments

Comments
 (0)