osmflat-rs icon indicating copy to clipboard operation
osmflat-rs copied to clipboard

Redundent transmute in osmflat_generated

Open hallahan opened this issue 3 years ago • 3 comments

Often times there are accessors that transmute the same time into itself such as:

https://github.com/boxdot/osmflat-rs/blob/011d70a90f784f8e60b1f4903e1367be454445d4/osmflat/src/osmflat_generated.rs#L494-L497

Is there any reason why this is being done, or is it something odd with the code generator? In this instance, the id is already an i64. Why transmute?

hallahan avatar Oct 25 '22 07:10 hallahan

This is due to the generator supporting to deserialize enumerations: Those need to be transmuted. The generator could theoretically skip the useless transmute by checking if target type matches source type, but the way it was implemented right now it just always transmutes, even if it is a no-op.

VeaaC avatar Oct 25 '22 11:10 VeaaC

I wonder if there is any performance hit?

hallahan avatar Oct 25 '22 15:10 hallahan

Only in debug mode, release mode optimizes everything away. Similarly the flatdata_read_bytes macro is fully optimized to generate code similar to C++ bitfields.

VeaaC avatar Oct 26 '22 06:10 VeaaC