about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-16 17:13:42 +0000
committerbors <bors@rust-lang.org>2023-08-16 17:13:42 +0000
commit6249c70dbb12d12b55f77b64fb0e71ac6c9ec806 (patch)
tree710a66754e5fd826789ac3375c34f126f48eb215
parentf99343f9eb09a156e49239c80bc0dec0915e121f (diff)
parentac0a8ca40d163c6f7a2724ac0c785cf0bf2e9ef4 (diff)
downloadrust-6249c70dbb12d12b55f77b64fb0e71ac6c9ec806.tar.gz
rust-6249c70dbb12d12b55f77b64fb0e71ac6c9ec806.zip
Auto merge of #3027 - ttsugriy:range-map, r=RalfJung
Avoid unnecessary Vec resize.

If `size > 0` current implementation will first create an empty vec and then push an element into it, which will cause a resize that can be easily avoided.

It's obviously not a big deal, but this also gets rid of `mut` local variable.
-rw-r--r--src/tools/miri/src/range_map.rs7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/tools/miri/src/range_map.rs b/src/tools/miri/src/range_map.rs
index 228a2396004..4a3670b76ac 100644
--- a/src/tools/miri/src/range_map.rs
+++ b/src/tools/miri/src/range_map.rs
@@ -27,11 +27,8 @@ impl<T> RangeMap<T> {
     #[inline(always)]
     pub fn new(size: Size, init: T) -> RangeMap<T> {
         let size = size.bytes();
-        let mut map = RangeMap { v: Vec::new() };
-        if size > 0 {
-            map.v.push(Elem { range: 0..size, data: init });
-        }
-        map
+        let v = if size > 0 { vec![Elem { range: 0..size, data: init }] } else { Vec::new() };
+        RangeMap { v }
     }
 
     /// Finds the index containing the given offset.