image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.87k stars 602 forks source link

Override `clone_from` implementations for a few types #2236

Closed a1phyr closed 3 months ago

a1phyr commented 4 months ago

I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to choose either at their option.

fintelia commented 4 months ago

How common is manually implementing clone_from? I don't think I've seen it done in other crates

fintelia commented 4 months ago

This would avoid the allocation but potentially "leak" memory if the image started out substantially larger than the new size. (Technically not a leak because the memory would still remain referenced but inaccessible.) Though perhaps that's well known behavior and folks using the method would expect that?

kornelski commented 4 months ago

I think it's fine that clone_from keeps potentially large allocations. It's opt-in, and its purpose is to reuse allocations.