libnxz / power-gzip

POWER NX zlib compliant library
23 stars 18 forks source link

Avoid goto when handling buffer states on nx_deflate #98

Closed mscastanho closed 3 years ago

mscastanho commented 3 years ago

For buffer states 0b0000 and 0b1000 we already know that:

  1. used_out is 0
  2. avail_in is 0
  3. used_in is 0

When the code jumps to s1 it will always end up in the same case, executing the code to handle the stream end, and the function will return from there. So we can move the code to a new function (nx_stream_end) and call it directly, returning it's result, avoiding the goto and making the code more readable.

Context: I've been investing some time to try to reorganize nx_deflate to make it easier to keep track of the states, transitions and code flow as whole. But it's requiring too many changes, so it's probably better to do it piece by piece over time instead of all at once. This PR is a small step towards that goal, as was #97