mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
642 stars 22 forks source link

fix: Generate a shadow `ordinal` field for Kotlin Enums #360

Closed mrousavy closed 2 days ago

mrousavy commented 2 days ago

Generates an added _ordinal field for every Kotlin Enum that can be accessed through fbjni.

Previously, we accessed ordinal, which should've been available in every Kotlin enum, but apparently some people had issues with this (@Szymon20000 & @shovel-kun) - maybe it got compiled out? Maybe it was an older Kotlin version? Maybe it got replaced with a ordinal() method for some reason? I don't know. I couldn't reproduce this bug.

Anyways; the smartest solution I can find that didn't degrade performance (calling ordinal() method thru JNI is slower than accessing a field) is that we just create a shadow-property on the Kotlin enum called _ordinal which mirrors whatever state the parent ordinal value or method has.

This can then be accessed directly from JNI as a field.

vercel[bot] commented 2 days ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **nitro-docs** | ⬜️ Skipped ([Inspect](https://vercel.com/margelo/nitro-docs/EeUnn9mrURTithRSZvgvrwgePvtM)) | | | Nov 20, 2024 1:17pm |