@@ -241,6 +241,7 @@ path = "{}.rs""#,
241
241
} ;
242
242
243
243
let mut current_line_number: usize = 1 ;
244
+ // Keep the last `CONTEXT` lines while iterating over the file lines.
244
245
let mut prev_lines: [ _ ; CONTEXT ] = array:: from_fn ( |_| String :: with_capacity ( 256 ) ) ;
245
246
let mut line = String :: with_capacity ( 256 ) ;
246
247
@@ -260,6 +261,7 @@ path = "{}.rs""#,
260
261
261
262
if contains_not_done_comment ( & line) {
262
263
let mut context = Vec :: with_capacity ( 2 * CONTEXT + 1 ) ;
264
+ // Previous lines.
263
265
for ( ind, prev_line) in prev_lines
264
266
. into_iter ( )
265
267
. take ( current_line_number - 1 )
@@ -273,18 +275,22 @@ path = "{}.rs""#,
273
275
} ) ;
274
276
}
275
277
278
+ // Current line.
276
279
context. push ( ContextLine {
277
280
line,
278
281
number : current_line_number,
279
282
important : true ,
280
283
} ) ;
281
284
285
+ // Next lines.
282
286
for ind in 0 ..CONTEXT {
283
287
let mut next_line = String :: with_capacity ( 256 ) ;
284
288
let Ok ( n) = read_line ( & mut next_line) else {
289
+ // If an error occurs, just ignore the next lines.
285
290
break ;
286
291
} ;
287
292
293
+ // Reached the end of the file.
288
294
if n == 0 {
289
295
break ;
290
296
}
@@ -300,10 +306,12 @@ path = "{}.rs""#,
300
306
}
301
307
302
308
current_line_number += 1 ;
303
- // Recycle the buffers .
309
+ // Add the current line as a previous line and shift the older lines by one .
304
310
for prev_line in & mut prev_lines {
305
311
mem:: swap ( & mut line, prev_line) ;
306
312
}
313
+ // The current line now contains the oldest previous line.
314
+ // Recycle it for reading the next line.
307
315
line. clear ( ) ;
308
316
}
309
317
}
0 commit comments