Reduce code duplication by separating current position manipulation and
entry zero-out.
Also use a single putLong() instead of two putInt()s, eliminating one
range check.
Overall this makes the two implementations much more similar, allowing
sharing code at some later point in the future.
JIRA: CONTROLLER-2095
Change-Id: I9791b5e27a779210b5500a7923ccada7156f26e5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
5b9d16d22b8645011f8a79167da4d31a46195327)
this.index.truncate(index);
if (index < segment.index()) {
- buffer.position(JournalSegmentDescriptor.BYTES);
- buffer.putInt(0);
- buffer.putInt(0);
+ // Reset the writer to the first entry.
buffer.position(JournalSegmentDescriptor.BYTES);
} else {
// Reset the writer to the given index.
reset(index);
-
- // Zero entries after the given index.
- int position = buffer.position();
- buffer.putInt(0);
- buffer.putInt(0);
- buffer.position(position);
}
+
+ // Zero the entry header at current buffer position.
+ int position = buffer.position();
+ // Note: we issue a single putLong() instead of two putInt()s.
+ buffer.putLong(0);
+ buffer.position(position);
}
@Override