stepcompress: Move check for add=0 sequences out of loop

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-12-18 21:56:30 -05:00
parent 6efadf44d0
commit 19d1f83d97
1 changed files with 9 additions and 1 deletions

View File

@ -132,6 +132,7 @@ compress_bisect_add(struct stepcompress *sc)
int32_t outer_mininterval = point.minp, outer_maxinterval = point.maxp; int32_t outer_mininterval = point.minp, outer_maxinterval = point.maxp;
int32_t add = 0, minadd = -0x8000, maxadd = 0x7fff; int32_t add = 0, minadd = -0x8000, maxadd = 0x7fff;
int32_t bestinterval = 0, bestcount = 1, bestadd = 1, bestreach = INT32_MIN; int32_t bestinterval = 0, bestcount = 1, bestadd = 1, bestreach = INT32_MIN;
int32_t zerointerval = 0, zerocount = 0;
for (;;) { for (;;) {
// Find longest valid sequence with the given 'add' // Find longest valid sequence with the given 'add'
@ -163,11 +164,15 @@ compress_bisect_add(struct stepcompress *sc)
// Check if this is the best sequence found so far // Check if this is the best sequence found so far
int32_t count = nextcount - 1, addfactor = count*(count-1)/2; int32_t count = nextcount - 1, addfactor = count*(count-1)/2;
int32_t reach = add*addfactor + interval*count; int32_t reach = add*addfactor + interval*count;
if (reach > bestreach && (bestadd || count > bestcount + bestcount/16)) { if (reach > bestreach) {
bestinterval = interval; bestinterval = interval;
bestcount = count; bestcount = count;
bestadd = add; bestadd = add;
bestreach = reach; bestreach = reach;
if (!add) {
zerointerval = interval;
zerocount = count;
}
} }
// Check if a greater or lesser add could extend the sequence // Check if a greater or lesser add could extend the sequence
@ -204,6 +209,9 @@ compress_bisect_add(struct stepcompress *sc)
break; break;
add = maxadd - (maxadd - minadd) / 4; add = maxadd - (maxadd - minadd) / 4;
} }
if (zerocount + zerocount/16 >= bestcount)
// Prefer add=0 if it's similar to the best found sequence
return (struct step_move){ zerointerval, zerocount, 0 };
return (struct step_move){ bestinterval, bestcount, bestadd }; return (struct step_move){ bestinterval, bestcount, bestadd };
} }