mirror of https://github.com/zkat/miette.git
misc(perf): nit perf improvements (#244)
This commit is contained in:
parent
a215720576
commit
566d6be6e3
|
|
@ -316,7 +316,7 @@ impl GraphicalReportHandler {
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<Box<dyn SpanContents<'_>>>, MietteError>>()
|
.collect::<Result<Vec<Box<dyn SpanContents<'_>>>, MietteError>>()
|
||||||
.map_err(|_| fmt::Error)?;
|
.map_err(|_| fmt::Error)?;
|
||||||
let mut contexts = Vec::new();
|
let mut contexts = Vec::with_capacity(contents.len());
|
||||||
for (right, right_conts) in labels.iter().cloned().zip(contents.iter()) {
|
for (right, right_conts) in labels.iter().cloned().zip(contents.iter()) {
|
||||||
if contexts.is_empty() {
|
if contexts.is_empty() {
|
||||||
contexts.push((right, right_conts));
|
contexts.push((right, right_conts));
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ Default trait implementations for [`SourceCode`].
|
||||||
*/
|
*/
|
||||||
use std::{
|
use std::{
|
||||||
borrow::{Cow, ToOwned},
|
borrow::{Cow, ToOwned},
|
||||||
|
collections::VecDeque,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
@ -19,7 +20,7 @@ fn context_info<'a>(
|
||||||
let mut line_count = 0usize;
|
let mut line_count = 0usize;
|
||||||
let mut start_line = 0usize;
|
let mut start_line = 0usize;
|
||||||
let mut start_column = 0usize;
|
let mut start_column = 0usize;
|
||||||
let mut before_lines_starts = Vec::new();
|
let mut before_lines_starts = VecDeque::new();
|
||||||
let mut current_line_start = 0usize;
|
let mut current_line_start = 0usize;
|
||||||
let mut end_lines = 0usize;
|
let mut end_lines = 0usize;
|
||||||
let mut post_span = false;
|
let mut post_span = false;
|
||||||
|
|
@ -34,10 +35,10 @@ fn context_info<'a>(
|
||||||
if offset < span.offset() {
|
if offset < span.offset() {
|
||||||
// We're before the start of the span.
|
// We're before the start of the span.
|
||||||
start_column = 0;
|
start_column = 0;
|
||||||
before_lines_starts.push(current_line_start);
|
before_lines_starts.push_back(current_line_start);
|
||||||
if before_lines_starts.len() > context_lines_before {
|
if before_lines_starts.len() > context_lines_before {
|
||||||
start_line += 1;
|
start_line += 1;
|
||||||
before_lines_starts.remove(0);
|
before_lines_starts.pop_front();
|
||||||
}
|
}
|
||||||
} else if offset >= span.offset() + span.len().saturating_sub(1) {
|
} else if offset >= span.offset() + span.len().saturating_sub(1) {
|
||||||
// We're after the end of the span, but haven't necessarily
|
// We're after the end of the span, but haven't necessarily
|
||||||
|
|
@ -73,7 +74,7 @@ fn context_info<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset >= (span.offset() + span.len()).saturating_sub(1) {
|
if offset >= (span.offset() + span.len()).saturating_sub(1) {
|
||||||
let starting_offset = before_lines_starts.first().copied().unwrap_or_else(|| {
|
let starting_offset = before_lines_starts.front().copied().unwrap_or_else(|| {
|
||||||
if context_lines_before == 0 {
|
if context_lines_before == 0 {
|
||||||
span.offset()
|
span.offset()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue