aptly icon indicating copy to clipboard operation
aptly copied to clipboard

Fix reflist diffs failing to compact when one of the inputs ends

Open refi64 opened this issue 2 years ago • 1 comments

The previous reflist logic would early-exit the loop body if one of the lists was empty, but that skips the compacting logic entirely.

Instead of doing the early-exit, we can leave a list's ref as nil when the list end is reached and then flip the comparison result, which will essentially treat it as being greater than all others. This should preserve the general behavior without omitting the compaction.


I suspect this might fix #282 and/or #287, but I haven't tested that.

An alternate approach in the same vein is to create a "sentinel" slice like:

sentinel := []byte{255}

and then use that when we reach the end of a reflist, which avoids the need to flip the comparison result. However, the code later on that checks if the ref is set would then look like:

if pl == nil && rl[0] != sentinel[0]

which felt worse to me while also being a tad wasteful (extra slice allocation every call!). That being said, omitting the comparison flip could certainly be seen as cleaner.

Checklist

  • [x] unit-test added (if change is algorithm)
  • [ ] functional test added/updated (if change is functional)
  • [ ] man page updated (if applicable)
  • [ ] bash completion updated (if applicable)
  • [ ] documentation updated
  • [x] author name in AUTHORS

refi64 avatar Nov 29 '23 00:11 refi64

CI failures seem to be unrelated? Looks like r-project updated their packages:

-Success downloading https://cloud.r-project.org/bin/linux/debian/bullseye-cran40/python3-rpy2-dbgsym_3.5.10-1~bullseyecran.0_amd64.deb
-Success downloading https://cloud.r-project.org/bin/linux/debian/bullseye-cran40/python3-rpy2-dbgsym_3.5.10-1~bullseyecran.0_i386.deb
+Success downloading https://cloud.r-project.org/bin/linux/debian/bullseye-cran40/littler_0.3.18-2~bullseyecran.0_all.deb
+Success downloading https://cloud.r-project.org/bin/linux/debian/bullseye-cran40/python3-rpy2-dbgsym_3.5.12-1~bullseyecran.0_amd64.deb

refi64 avatar Nov 29 '23 14:11 refi64