aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-12-18 21:56:30 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-12-19 11:20:38 -0500
commit19d1f83d976ada91c81d509af2aeafae25e64fae (patch)
treeb9e17bc39d7516c689d6a7381b52315bb2bd0707 /klippy
parent6efadf44d0ca34505e024a90bf6e8c169d36402e (diff)
downloadkutter-19d1f83d976ada91c81d509af2aeafae25e64fae.tar.gz
kutter-19d1f83d976ada91c81d509af2aeafae25e64fae.tar.xz
kutter-19d1f83d976ada91c81d509af2aeafae25e64fae.zip
stepcompress: Move check for add=0 sequences out of loop
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/stepcompress.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/klippy/stepcompress.c b/klippy/stepcompress.c
index 0ae3bd57..75e8e819 100644
--- a/klippy/stepcompress.c
+++ b/klippy/stepcompress.c
@@ -132,6 +132,7 @@ compress_bisect_add(struct stepcompress *sc)
int32_t outer_mininterval = point.minp, outer_maxinterval = point.maxp;
int32_t add = 0, minadd = -0x8000, maxadd = 0x7fff;
int32_t bestinterval = 0, bestcount = 1, bestadd = 1, bestreach = INT32_MIN;
+ int32_t zerointerval = 0, zerocount = 0;
for (;;) {
// 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
int32_t count = nextcount - 1, addfactor = count*(count-1)/2;
int32_t reach = add*addfactor + interval*count;
- if (reach > bestreach && (bestadd || count > bestcount + bestcount/16)) {
+ if (reach > bestreach) {
bestinterval = interval;
bestcount = count;
bestadd = add;
bestreach = reach;
+ if (!add) {
+ zerointerval = interval;
+ zerocount = count;
+ }
}
// Check if a greater or lesser add could extend the sequence
@@ -204,6 +209,9 @@ compress_bisect_add(struct stepcompress *sc)
break;
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 };
}