Skip to content

Commit 2fd2b91

Browse files
authored
[perf] Use faster check to early-return from extract_comments_to_line (#824)
1 parent ac5d704 commit 2fd2b91

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

librubyfmt/src/file_comments.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,17 @@ impl FileComments {
212212
line_number: LineNumber,
213213
) -> Option<(CommentBlock, LineNumber)> {
214214
let lowest_line = self.other_comments.first().map(|(ln, _)| *ln)?;
215-
let split_point = self
216-
.other_comments
217-
.partition_point(|(ln, _)| *ln <= line_number);
218-
219-
if split_point == 0 {
215+
if lowest_line > line_number {
220216
return Some((
221217
CommentBlock::new(lowest_line..line_number + 1, Vec::new()),
222218
starting_line_number,
223219
));
224220
}
225221

222+
let split_point = self
223+
.other_comments
224+
.partition_point(|(ln, _)| *ln <= line_number);
225+
226226
let mut comment_block_with_spaces: Vec<String> = Vec::new();
227227
let mut last_line = None;
228228

0 commit comments

Comments
 (0)