clippy: fix warnings in various modules in components (#31568)

* clippy: fix warnings in various modules in components

* fix: unit tests

* fix: build on android

* fix: all samplers use new_boxed
This commit is contained in:
eri 2024-03-08 15:28:04 +01:00 committed by GitHub
parent 19f1f2a8f4
commit 3a5ca785d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 107 additions and 118 deletions

View file

@ -184,9 +184,9 @@ impl Profiler {
})
.expect("Thread spawning failed");
// decide if we need to spawn the timer thread
match option {
&OutputOptions::FileName(_) => { /* no timer thread needed */ },
&OutputOptions::Stdout(period) => {
match *option {
OutputOptions::FileName(_) => { /* no timer thread needed */ },
OutputOptions::Stdout(period) => {
// Spawn a timer thread
let chan = chan.clone();
thread::Builder::new()
@ -241,11 +241,11 @@ impl Profiler {
output: Option<OutputOptions>,
) -> Profiler {
Profiler {
port: port,
port,
buckets: BTreeMap::new(),
output: output,
output,
last_msg: None,
trace: trace,
trace,
blocked_layout_queries: HashMap::new(),
}
}
@ -259,7 +259,7 @@ impl Profiler {
}
fn find_or_insert(&mut self, k: (ProfilerCategory, Option<TimerMetadata>), t: f64) {
self.buckets.entry(k).or_insert_with(Vec::new).push(t);
self.buckets.entry(k).or_default().push(t);
}
fn handle_msg(&mut self, msg: ProfilerMsg) -> bool {
@ -321,24 +321,24 @@ impl Profiler {
match self.output {
Some(OutputOptions::FileName(ref filename)) => {
let path = Path::new(&filename);
let mut file = match File::create(&path) {
let mut file = match File::create(path) {
Err(e) => panic!("Couldn't create {}: {}", path.display(), e),
Ok(file) => file,
};
write!(
writeln!(
file,
"_category_\t_incremental?_\t_iframe?_\t_url_\t_mean (ms)_\t\
_median (ms)_\t_min (ms)_\t_max (ms)_\t_events_\n"
_median (ms)_\t_min (ms)_\t_max (ms)_\t_events_"
)
.unwrap();
for (&(ref category, ref meta), ref mut data) in &mut self.buckets {
for ((category, meta), ref mut data) in &mut self.buckets {
data.sort_by(|a, b| a.partial_cmp(b).expect("No NaN values in profiles"));
let data_len = data.len();
if data_len > 0 {
let (mean, median, min, max) = Self::get_statistics(data);
write!(
writeln!(
file,
"{}\t{}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15}\n",
"{}\t{}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15}",
category.format(&self.output),
meta.format(&self.output),
mean,
@ -351,9 +351,9 @@ impl Profiler {
}
}
write!(file, "_url\t_blocked layout queries_\n").unwrap();
writeln!(file, "_url\t_blocked layout queries_").unwrap();
for (url, count) in &self.blocked_layout_queries {
write!(file, "{}\t{}\n", url, count).unwrap();
writeln!(file, "{}\t{}", url, count).unwrap();
}
},
Some(OutputOptions::Stdout(_)) => {
@ -374,7 +374,7 @@ impl Profiler {
" _events_"
)
.unwrap();
for (&(ref category, ref meta), ref mut data) in &mut self.buckets {
for ((category, meta), ref mut data) in &mut self.buckets {
data.sort_by(|a, b| a.partial_cmp(b).expect("No NaN values in profiles"));
let data_len = data.len();
if data_len > 0 {
@ -393,13 +393,13 @@ impl Profiler {
.unwrap();
}
}
writeln!(&mut lock, "").unwrap();
writeln!(&mut lock).unwrap();
writeln!(&mut lock, "_url_\t_blocked layout queries_").unwrap();
for (url, count) in &self.blocked_layout_queries {
writeln!(&mut lock, "{}\t{}", url, count).unwrap();
}
writeln!(&mut lock, "").unwrap();
writeln!(&mut lock).unwrap();
},
None => { /* Do nothing if no output option has been set */ },
};