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.
This commit is contained in:
commit
6249c70dbb
@ -27,11 +27,8 @@ impl<T> RangeMap<T> {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn new(size: Size, init: T) -> RangeMap<T> {
|
pub fn new(size: Size, init: T) -> RangeMap<T> {
|
||||||
let size = size.bytes();
|
let size = size.bytes();
|
||||||
let mut map = RangeMap { v: Vec::new() };
|
let v = if size > 0 { vec![Elem { range: 0..size, data: init }] } else { Vec::new() };
|
||||||
if size > 0 {
|
RangeMap { v }
|
||||||
map.v.push(Elem { range: 0..size, data: init });
|
|
||||||
}
|
|
||||||
map
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the index containing the given offset.
|
/// Finds the index containing the given offset.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user