From 7bdd6479ce43d6b45803fd0bc4b363370975ceab Mon Sep 17 00:00:00 2001 From: Paul Eggert
Date: Wed, 3 Sep 2014 15:25:21 -0700 Subject: [PATCH 1/3] diff: fix performance bug with prefix computation * src/io.c (find_identical_ends): Fix performance bug: the test for when the prefix was needed messed up by the 2002-02-28 integer-overflow fixes, causing performance to be worse than it needed to be. --- src/io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/io.c b/src/io.c index 05a898c..1a8b936 100644 --- a/src/io.c +++ b/src/io.c @@ -538,6 +538,7 @@ find_identical_ends (struct file_data filevec[]) lin i, lines; size_t n0, n1; lin alloc_lines0, alloc_lines1; + bool prefix_needed; lin buffered_prefix, prefix_count, prefix_mask; lin middle_guess, suffix_guess; @@ -687,12 +688,13 @@ find_identical_ends (struct file_data filevec[]) prefix_mask = prefix_count - 1; lines = 0; linbuf0 = xmalloc (alloc_lines0 * sizeof *linbuf0); + prefix_needed = ! (no_diff_means_no_output + && filevec[0].prefix_end == p0 + && filevec[1].prefix_end == p1); p0 = buffer0; /* If the prefix is needed, find the prefix lines. */ - if (! (no_diff_means_no_output - && filevec[0].prefix_end == p0 - && filevec[1].prefix_end == p1)) + if (prefix_needed) { end0 = filevec[0].prefix_end; while (p0 != end0) -- 1.9.3