vortex
vortex copied to clipboard
Reconsider EncodingRef
Currently we pass around EncodingRef to represent an encoding. It's type-defed to be a &'static dyn Encoding.
Most of our encodings are zero-sized structs, so this is pretty trivial to create. There are also a relatively small number of builtin encodings.
However, with #886 we added an OpaqueEncoding. This one actually is not zero-sized, but takes a u16 to keep track of the (unknown) encoding ID that it wraps. Instances are dynamically created in response to unknown encodings encountered in deserialization, and currently to keep with EncodingRef, we need to Box::leak to get the static reference.
There are a few alternatives
- Make
Contextcarry around a set ofopaque_encodings. Care would need to be taken to make sure this collection is safe for concurrent updates - Change EncodingRef to be an
Arc<dyn Encoding>. This will create an allocation for the builtin encodings whereas now there are none. However, there are only 25 builtin encodings, not that much to be allocating.