Skip to content

Commit 6249c70

Browse files
committedAug 16, 2023
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.
2 parents f99343f + ac0a8ca commit 6249c70

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed
 

Diff for: ‎src/tools/miri/src/range_map.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ impl<T> RangeMap<T> {
2727
#[inline(always)]
2828
pub fn new(size: Size, init: T) -> RangeMap<T> {
2929
let size = size.bytes();
30-
let mut map = RangeMap { v: Vec::new() };
31-
if size > 0 {
32-
map.v.push(Elem { range: 0..size, data: init });
33-
}
34-
map
30+
let v = if size > 0 { vec![Elem { range: 0..size, data: init }] } else { Vec::new() };
31+
RangeMap { v }
3532
}
3633

3734
/// Finds the index containing the given offset.

0 commit comments

Comments
 (0)