3f645f980c
These callbacks are used for marshaling by callables and generic Godot collections. C# generics don't support specialization the way C++ templates do. I knew NativeAOT could optimize away many type checks when the types are known at compile time, but I didn't trust the JIT would do as good a job, so I initially went with cached function pointers. Well, it turns out the JIT is also very good at optimizing in this scenario, so I'm changing the methods to do the conversion directly, rather than returning a function pointer for the conversion. The methods were moved to `VariantUtils`, and were renamed from `GetFromVariantCallback/GetToVariantCallback` to `ConvertTo/CreateFrom`. The new implementation looks like it goes through many `if` checks at runtime to find the right branch for the type, but in practice it works pretty much like template specialization. The JIT only generates code for the relevant branch. Together with inlining, the result is very close or the same as doing the conversion manually: ```cs godot_variant variant; int foo = variant.Int; int bar = VariantUtils.ConvertTo<int>(variant); ``` If the type is a generic Godot collection, the conversion still goes through a function pointer call. The new code happens to be much shorter as well, with the file going from 1057 lines to 407. Side note: `Variant.cs` was mistakenly created in the wrong folder, so I moved it to the `Core` folder. |
||
---|---|---|
.. | ||
basis_universal | ||
bmp | ||
camera | ||
csg | ||
cvtt | ||
dds | ||
denoise | ||
enet | ||
etcpak | ||
freetype | ||
gdscript | ||
glslang | ||
gltf | ||
gridmap | ||
hdr | ||
jpg | ||
jsonrpc | ||
lightmapper_rd | ||
mbedtls | ||
meshoptimizer | ||
minimp3 | ||
mobile_vr | ||
mono | ||
msdfgen | ||
multiplayer | ||
navigation | ||
noise | ||
ogg | ||
openxr | ||
raycast | ||
regex | ||
squish | ||
svg | ||
text_server_adv | ||
text_server_fb | ||
tga | ||
theora | ||
tinyexr | ||
upnp | ||
vhacd | ||
vorbis | ||
webp | ||
webrtc | ||
websocket | ||
webxr | ||
xatlas_unwrap | ||
zip | ||
modules_builders.py | ||
register_module_types.h | ||
SCsub |