Improve Message sorting performance (#4624)

This commit is contained in:
Micha Reiser 2023-05-24 16:34:48 +02:00 committed by GitHub
parent 17d938f078
commit 85f094f592
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 10 deletions

View file

@ -6,6 +6,7 @@ use std::ops::Deref;
use ruff_text_size::{TextRange, TextSize};
use rustc_hash::FxHashMap;
use crate::jupyter::JupyterIndex;
pub use azure::AzureEmitter;
pub use github::GithubEmitter;
pub use gitlab::GitlabEmitter;
@ -17,9 +18,6 @@ use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix};
use ruff_python_ast::source_code::{SourceFile, SourceLocation};
pub use text::TextEmitter;
use crate::jupyter::JupyterIndex;
use crate::registry::AsRule;
mod azure;
mod diff;
mod github;
@ -77,11 +75,7 @@ impl Message {
impl Ord for Message {
fn cmp(&self, other: &Self) -> Ordering {
(self.filename(), self.start(), self.kind.rule()).cmp(&(
other.filename(),
other.start(),
other.kind.rule(),
))
(&self.file, self.start()).cmp(&(&other.file, other.start()))
}
}

View file

@ -143,7 +143,8 @@ pub(crate) fn run(
acc
});
diagnostics.messages.sort_unstable();
diagnostics.messages.sort();
let duration = start.elapsed();
debug!("Checked {:?} files in: {:?}", paths.len(), duration);

View file

@ -107,7 +107,7 @@ quoting the executed command, along with the relevant file contents and `pyproje
#[cfg(windows)]
assert!(colored::control::set_virtual_terminal(true).is_ok());
let log_level: LogLevel = (&log_level_args).into();
let log_level = LogLevel::from(&log_level_args);
set_up_logging(&log_level)?;
match command {

View file

@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
@ -207,6 +208,23 @@ impl SourceFile {
}
}
impl PartialOrd for SourceFile {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SourceFile {
fn cmp(&self, other: &Self) -> Ordering {
// Short circuit if these are the same source files
if Arc::ptr_eq(&self.inner, &other.inner) {
Ordering::Equal
} else {
self.inner.name.cmp(&other.inner.name)
}
}
}
struct SourceFileInner {
name: Box<str>,
code: Box<str>,