Skip to content

Commit 078f6ff

Browse files
committed
Add comments
1 parent 7a6f71f commit 078f6ff

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/exercise.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ path = "{}.rs""#,
241241
};
242242

243243
let mut current_line_number: usize = 1;
244+
// Keep the last `CONTEXT` lines while iterating over the file lines.
244245
let mut prev_lines: [_; CONTEXT] = array::from_fn(|_| String::with_capacity(256));
245246
let mut line = String::with_capacity(256);
246247

@@ -260,6 +261,7 @@ path = "{}.rs""#,
260261

261262
if contains_not_done_comment(&line) {
262263
let mut context = Vec::with_capacity(2 * CONTEXT + 1);
264+
// Previous lines.
263265
for (ind, prev_line) in prev_lines
264266
.into_iter()
265267
.take(current_line_number - 1)
@@ -273,18 +275,22 @@ path = "{}.rs""#,
273275
});
274276
}
275277

278+
// Current line.
276279
context.push(ContextLine {
277280
line,
278281
number: current_line_number,
279282
important: true,
280283
});
281284

285+
// Next lines.
282286
for ind in 0..CONTEXT {
283287
let mut next_line = String::with_capacity(256);
284288
let Ok(n) = read_line(&mut next_line) else {
289+
// If an error occurs, just ignore the next lines.
285290
break;
286291
};
287292

293+
// Reached the end of the file.
288294
if n == 0 {
289295
break;
290296
}
@@ -300,10 +306,12 @@ path = "{}.rs""#,
300306
}
301307

302308
current_line_number += 1;
303-
// Recycle the buffers.
309+
// Add the current line as a previous line and shift the older lines by one.
304310
for prev_line in &mut prev_lines {
305311
mem::swap(&mut line, prev_line);
306312
}
313+
// The current line now contains the oldest previous line.
314+
// Recycle it for reading the next line.
307315
line.clear();
308316
}
309317
}

0 commit comments

Comments
 (0)