Skip to content
Myr

Use slices instead of borrowed vectors

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by philipp · committed by David Peter · parent f3f8c9c · Browse files · 7 files+11 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+11 added−11 removed

  • other:+11 added−11 removed

7 files+11 added−11 removed

modified:src/hyperfine/export/asciidoc.rs+1 added-1 removed
8 unmodified lines
9#[derive(Default)]10pub struct AsciidocExporter {}1112impl Exporter for AsciidocExporter {13 fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>> {13 fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {14 let unit = if let Some(unit) = unit {15 // Use the given unit for all entries.16 unit17 } else if let Some(first_result) = results.first() {
203 unmodified lines
modified:src/hyperfine/export/csv.rs+1 added-1 removed
9 unmodified lines
10#[derive(Default)]11pub struct CsvExporter {}1213impl Exporter for CsvExporter {14 fn serialize(&self, results: &Vec<BenchmarkResult>, _unit: Option<Unit>) -> Result<Vec<u8>> {14 fn serialize(&self, results: &[BenchmarkResult], _unit: Option<Unit>) -> Result<Vec<u8>> {15 let mut writer = WriterBuilder::new().from_writer(vec![]);16 for res in results {17 // The list of times cannot be exported to the CSV file - remove it:18 let mut result = res.clone();
10 unmodified lines
modified:src/hyperfine/export/json.rs+2 added-2 removed
7 unmodified lines
8use serde_json::to_vec_pretty;910#[derive(Serialize, Debug)]11struct HyperfineSummary<'a> {12 results: &'a Vec<BenchmarkResult>,12 results: &'a [BenchmarkResult],13}1415#[derive(Default)]16pub struct JsonExporter {}1718impl Exporter for JsonExporter {19 fn serialize(&self, results: &Vec<BenchmarkResult>, _unit: Option<Unit>) -> Result<Vec<u8>> {19 fn serialize(&self, results: &[BenchmarkResult], _unit: Option<Unit>) -> Result<Vec<u8>> {20 let mut output = to_vec_pretty(&HyperfineSummary { results });21 for content in output.iter_mut() {22 content.push(b'\n');23 }
4 unmodified lines
modified:src/hyperfine/export/markdown.rs+2 added-2 removed
9 unmodified lines
10#[derive(Default)]11pub struct MarkdownExporter {}1213impl Exporter for MarkdownExporter {14 fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>> {14 fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {15 let unit = if let Some(unit) = unit {16 // Use the given unit for all entries.17 unit18 } else if let Some(first_result) = results.first() {
3 unmodified lines
22 // Default to `Second`.23 Unit::Second24 };2526 let annotated_results = compute_relative_speed(&results);26 let annotated_results = compute_relative_speed(results);2728 let mut destination = start_table(unit);2930 for result in annotated_results {
240 unmodified lines
modified:src/hyperfine/export/mod.rs+2 added-2 removed
31 unmodified lines
3233/// Interface for different exporters.34trait Exporter {35 /// Export the given entries in the serialized form.36 fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>>;36 fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>>;37}3839struct ExporterWithFilename {40 exporter: Box<dyn Exporter>,
37 unmodified lines
78 }79}8081/// Write the given content to a file with the specified name82fn write_to_file(filename: &String, content: &Vec<u8>) -> Result<()> {82fn write_to_file(filename: &String, content: &[u8]) -> Result<()> {83 let mut file = File::create(filename)?;84 file.write_all(content)85}
modified:src/hyperfine/internal.rs+2 added-2 removed
55 unmodified lines
56 l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)57}5859pub fn compute_relative_speed<'a>(60 results: &'a Vec<BenchmarkResult>,60 results: &'a [BenchmarkResult],61) -> Vec<BenchmarkResultWithRelativeSpeed<'a>> {62 let fastest: &BenchmarkResult = results63 .iter()64 .min_by(|&l, &r| compare_mean_time(l, r))
18 unmodified lines
83 })84 .collect()85}8687pub fn write_benchmark_comparison(results: &Vec<BenchmarkResult>) {87pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {88 if results.len() < 2 {89 return;90 }91
57 unmodified lines
modified:src/main.rs+1 added-1 removed
26 unmodified lines
27}2829/// Runs the benchmark for the given commands30fn run(31 commands: &Vec<Command<'_>>,31 commands: &[Command<'_>],32 options: &HyperfineOptions,33) -> io::Result<Vec<BenchmarkResult>> {34 let shell_spawning_time =35 mean_shell_spawning_time(&options.shell, &options.output_style, options.show_output)?;
190 unmodified lines