Skip to content

Commit

Permalink
Decrease counts in one place rather than two
Browse files Browse the repository at this point in the history
Prep for future refactorings.
  • Loading branch information
walles committed Feb 4, 2024
1 parent ef29db7 commit 3fa9e68
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/hunk_highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ impl LinesHighlighter for HunkLinesHighlighter {
});
}

let prefix_length = self.expected_line_counts.len() - 1;
let spaces_only = " ".repeat(prefix_length);
let prefix = if line.len() >= prefix_length {
line.split_at(prefix_length).0
} else {
spaces_only.as_str()
};
self.decrease_expected_line_counts(prefix)?;

// Context lines
let spaces_only = " ".repeat(self.expected_line_counts.len() - 1);
if line.is_empty() || line.starts_with(&spaces_only) {
return_me.append(&mut self.drain(thread_pool));

self.decrease_expected_line_counts(&spaces_only)?;

// FIXME: Consider whether we should be coalescing the plain lines?
// Maybe that would improve performance? Measure and find out!
return_me.push(StringFuture::from_string(line.to_string() + "\n"));
Expand Down Expand Up @@ -160,8 +166,6 @@ impl HunkLinesHighlighter {
text.push_str(line);
text.push('\n');

self.decrease_expected_line_counts(prefix)?;

return Ok(Response {
// Even if we don't expect any more lines, we could still receive a
// `\ No newline at end of file` line after this one.
Expand Down

0 comments on commit 3fa9e68

Please sign in to comment.