beef icon indicating copy to clipboard operation
beef copied to clipboard

Implement `beef::lean::Cow` on other pointer widths

Open Waelwindows opened this issue 4 years ago • 1 comments

This should remove the restriction on beef::lean::Cow being only available on targets with a pointer width of 64

Waelwindows avatar Jun 08 '21 23:06 Waelwindows

This is, strictly speaking, a breaking change, since on 32 bit targets lean::Cow switches from supporting u32::MAX elements to u16::MAX elements. (On 16 bit pointer targets, it goes from u16::MAX to u8::MAX elements. Ignoring 16 bit pointers from hereon.)

There's advantages to both ways. With usize lean::Cow, you always fit the cow into 2×usize. With u64 lean::Cow, the cow always supports u32::MAX elements, which is enough for (nearly) anyone, since you'll (typically) run out of RAM first.

lean::Cow is more necessary on 64 bit architectures, where pointers are ~~thicc~~ quite large comparatively. It's reasonable to use lean::Cow so save the space on 64 bit targets by restricting the capacity as if it were a 32 bit target, but still wanting to keep the extra space on 32bit (which is still less than 64bit lean) to keep the same max capacity.

I think there is value in exposing the 2×usize version to 32 bit architectures, but it should be under a new reëxport (beef::leaner::Cow? skim::Cow?), and documentation would need to be made extra clear so that it's clear from both 64bit and 32bit docs what the behavior is on both targets.

CAD97 avatar Jun 09 '21 02:06 CAD97