From 642f9640b8f2239386c985761381ec0c9dbada65 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 8 Apr 2024 12:29:54 -0700 Subject: [PATCH] metrics: tests: replace .get(N).unwrap() with array indexing This is more concise and accomplishes the same thing. It also incidentally avoids a clippy warning about using .get(0) instead of .first(). BUG=b:344974550 TEST=tools/clippy Change-Id: Ie8575f63ca7aacd91123c81a6f533b4a2d1408d2 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5598299 Commit-Queue: Daniel Verkamp Reviewed-by: Noah Gold --- metrics/src/local_stats.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/metrics/src/local_stats.rs b/metrics/src/local_stats.rs index 9f6601cb238..fb0479677f8 100644 --- a/metrics/src/local_stats.rs +++ b/metrics/src/local_stats.rs @@ -571,9 +571,9 @@ mod tests { simple_stats.add(v); } - bucket_check(histogram.buckets.get(0).unwrap(), &[0, 9, 5]); - bucket_check(histogram.buckets.get(1).unwrap(), &[20, 50]); - bucket_check(histogram.buckets.get(2).unwrap(), &[199, 120]); + bucket_check(&histogram.buckets[0], &[0, 9, 5]); + bucket_check(&histogram.buckets[1], &[20, 50]); + bucket_check(&histogram.buckets[2], &[199, 120]); assert_eq!(histogram.buckets.len(), 3); assert_eq!(histogram.simple_stat(), simple_stats); assert_eq!(histogram.values, None); @@ -592,9 +592,9 @@ mod tests { simple_stats.add(v); } - bucket_check(histogram.buckets.get(1).unwrap(), &[4, 9, 5]); - bucket_check(histogram.buckets.get(2).unwrap(), &[20, 50]); - bucket_check(histogram.buckets.get(3).unwrap(), &[199, 120]); + bucket_check(&histogram.buckets[1], &[4, 9, 5]); + bucket_check(&histogram.buckets[2], &[20, 50]); + bucket_check(&histogram.buckets[3], &[199, 120]); assert_eq!(histogram.buckets.len(), 5); assert_eq!(histogram.simple_stat(), simple_stats); assert_eq!(histogram.values, None); @@ -637,9 +637,9 @@ mod tests { histogram.add(v.clone()).unwrap(); } - bucket_check(histogram.buckets.get(0).unwrap(), &[4, 9, 5]); - bucket_check(histogram.buckets.get(1).unwrap(), &[20, 50]); - bucket_check(histogram.buckets.get(2).unwrap(), &[199, 120]); + bucket_check(histogram.buckets[0], &[4, 9, 5]); + bucket_check(histogram.buckets[1], &[20, 50]); + bucket_check(histogram.buckets[2], &[199, 120]); assert_eq!(histogram.buckets.len(), 3); assert_eq!(histogram.simple_stat(), simple_stats); assert_eq!(histogram.values, Some(values)); @@ -661,11 +661,11 @@ mod tests { histogram.add(v.clone()).unwrap(); } - bucket_check(histogram.buckets.get(0).unwrap(), &[]); - bucket_check(histogram.buckets.get(4).unwrap(), &[]); - bucket_check(histogram.buckets.get(1).unwrap(), &[4, 9, 5]); - bucket_check(histogram.buckets.get(2).unwrap(), &[20, 50]); - bucket_check(histogram.buckets.get(3).unwrap(), &[199, 120]); + bucket_check(histogram.buckets[0], &[]); + bucket_check(histogram.buckets[4], &[]); + bucket_check(histogram.buckets[1], &[4, 9, 5]); + bucket_check(histogram.buckets[2], &[20, 50]); + bucket_check(histogram.buckets[3], &[199, 120]); assert_eq!(histogram.buckets.len(), 5); assert_eq!(histogram.simple_stat(), simple_stats); assert_eq!(histogram.values, Some(values));