pub fn repeat<D, C>(
out: &mut Vec<D>,
len: usize,
counts: &[C],
total: usize,
item: impl Fn(usize) -> D,
)Expand description
Appends item(j) for each j below len, as many times as its count. counts holds one count for all the items, or one for each item. The counts are nonnegative and sum to total. An item with a count of at most 4 writes four copies where its run starts. The items after it overwrite the copies beyond its count. A larger count fills its run. With a count for each item, a group of 4 items whose counts are all at most 4 writes its copies after one check for the whole group. With a check and a taken branch for each item, the loop’s cost varied by about a third with where its code was placed.