RustAudio / lewton

Rust vorbis decoder
Other
261 stars 26 forks source link

Avoid allocating a vector in loop in `read_audio_packet_generic` #68

Closed AnthonyMikh closed 5 years ago

AnthonyMikh commented 5 years ago

Fixes a TODO in code

est31 commented 5 years ago

Thanks but it's still a copy. The comment should remain.

AnthonyMikh commented 5 years ago

Well, at least it avoids allocating a Vec in loop.

est31 commented 5 years ago

That isn't avoided either, because empty vec's don't allocate. But I'll merge it because it saves a line.

Luni-4 commented 5 years ago

@est31 @AnthonyMikh

Could copy_from_slice solve the problem?

Something like this:

let vec_at_ch = &vectors[resid_vec_len * ch .. resid_vec_len * (ch + 1)];
residue_vectors[j].copy_from_slice(vec_at_ch);
est31 commented 5 years ago

copy_from_slice would still do a copy. You'd also have to 0-initialize the vec meaning an additional step, which makes extend_from_slice better.

Luni-4 commented 5 years ago

copy_from_slice would still do a copy. You'd also have to 0-initialize the vec meaning an additional step, which makes extend_from_slice better.

Oh, just looked at the entire code and seen that residue_vectors isn't allocated, I thought it was. Disregard my comment then :)