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
Provenance
- Commit
c0ada7d- Tree
6e6f72c- Author
philipp <philipp>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
f3f8c9c
7 files changed+11 added−11 removed
modified:src/hyperfine/export/asciidoc.rs+1 added-1 removed
8 unmodified lines9 #[derive(Default)]10 pub struct AsciidocExporter {}11 12 impl 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 linesmodified:src/hyperfine/export/csv.rs+1 added-1 removed
9 unmodified lines10 #[derive(Default)]11 pub struct CsvExporter {}12 13 impl 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 linesmodified:src/hyperfine/export/json.rs+2 added-2 removed
7 unmodified lines8 use serde_json::to_vec_pretty;9 10 #[derive(Serialize, Debug)]11 struct HyperfineSummary<'a> {12- results: &'a Vec<BenchmarkResult>,12+ results: &'a [BenchmarkResult],13 }14 15 #[derive(Default)]16 pub struct JsonExporter {}17 18 impl 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 linesmodified:src/hyperfine/export/markdown.rs+2 added-2 removed
9 unmodified lines10 #[derive(Default)]11 pub struct MarkdownExporter {}12 13 impl 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 lines22 // Default to `Second`.23 Unit::Second24 };25 26- let annotated_results = compute_relative_speed(&results);26+ let annotated_results = compute_relative_speed(results);27 28 let mut destination = start_table(unit);29 30 for result in annotated_results {240 unmodified linesmodified:src/hyperfine/export/mod.rs+2 added-2 removed
31 unmodified lines32 33 /// Interface for different exporters.34 trait 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 }38 39 struct ExporterWithFilename {40 exporter: Box<dyn Exporter>,37 unmodified lines78 }79 }80 81 /// Write the given content to a file with the specified name82-fn write_to_file(filename: &String, content: &Vec<u8>) -> Result<()> {82+fn 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 lines56 l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)57 }58 59 pub 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 lines83 })84 .collect()85 }86 87-pub fn write_benchmark_comparison(results: &Vec<BenchmarkResult>) {87+pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {88 if results.len() < 2 {89 return;90 }91 57 unmodified linesmodified:src/main.rs+1 added-1 removed
26 unmodified lines27 }28 29 /// Runs the benchmark for the given commands30 fn 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