Skip to content

Commit

Permalink
clarify comments
Browse files Browse the repository at this point in the history
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
  • Loading branch information
blt committed Oct 24, 2024
1 parent ec2fc2d commit 5424a84
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lading_payload/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,17 @@ impl Cache {
usize::try_from(offset).expect("offset larger than machine word bytes");

while remaining > 0 {
// Compute offset within the cycle
let offset_within_cycle = current_offset % total_cycle_size;
// The plan is this. We treat the blocks as one infinite cycle. We
// map our offset into the domain of the blocks, then seek forward
// until we find the block we need to start reading from. Then we
// read into `data`.

// Find which block this offset falls into
let offset_within_cycle = current_offset % total_cycle_size;
let mut block_start = 0;
for block in blocks {
let block_size = block.total_bytes.get() as usize;
if offset_within_cycle < block_start + block_size {
// Offset is within this block
// Offset is within this block. Begin reading into `data`.
let block_offset = offset_within_cycle - block_start;
let bytes_in_block = (block_size - block_offset).min(remaining);

Expand Down

0 comments on commit 5424a84

Please sign in to comment.