optimize hed_file_commit: Kill commit_current()
commite11759c3b120e9c81892f38414539aa73be1bd90
authorPetr Tesarik <petr@tesarici.cz>
Fri, 2 Nov 2012 13:15:41 +0000 (2 14:15 +0100)
committerPetr Tesarik <petr@tesarici.cz>
Fri, 2 Nov 2012 13:15:41 +0000 (2 14:15 +0100)
treeb7f3655bebd53b8e34ffcbe10204850d73650177
parent215fd62315de581b4aead96221547d106a534e61
optimize hed_file_commit: Kill commit_current()

Both call sites for commit_current() can be converted to call
commit_forwards() directly.

A. FLUSHING BUFFERS BEFORE SKIPPED BLOCKS

Since blocks can be skipped only if they have zero shift, we can't see
negative shift here. This is obvious from the enclosing conditional,
but it is correct also semantically, because a skipped block can be
preceded by:

a. a negative-shift chunk, which is committed at the end of the previous
   iteration of the main loop, or
b. a non-negative shift chunk, which is now handled with commit_forwards()

B. FLUSHING BUFFERS AT END OF FILE

The main loop terminates on the terminating block. However, this block
always has the EOF flag, so the shift must be always set to zero after
the last iteration of the main loop.

Note that if there is nothing to commit, there is no difference between
calling commit_forwards() and calling commit_backwards(). Both do nothing.
libhed/file.c