flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

[TS] In version 2, why do union helpers use string comparison?

Open stephanemagnenat opened this issue 4 years ago • 17 comments
trafficstars

In version 2, union helpers in the form of unionToAnyX are generated. Inside them, there is a switch of type:

 switch(AnyX[type]) {
    case 'NONE': return null; 
    ...
}

Where type is the actual enum with variants defined as integers starting from 0. So, why not switching directly on type, like:

 switch(type) {
    case '0' /* NONE */: return null; 
    ...
}

as the code is generated anyway?

Moreover, it might make sense to use const enums for performance reasons, if the added constraints on the API are acceptable.

stephanemagnenat avatar Jul 19 '21 16:07 stephanemagnenat

@bjornharrtell

aardappel avatar Jul 19 '21 18:07 aardappel

Will need to look into it more to see what would be good to do, but seems to be sound observations.

bjornharrtell avatar Jul 19 '21 21:07 bjornharrtell

This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

github-actions[bot] avatar Jan 18 '22 20:01 github-actions[bot]

Commenting to avoid stale issue. I think this should be addressed.

sketch34 avatar Jan 19 '22 04:01 sketch34

For the record, unfortunately, I have no current plans to spend time on this myself.

bjornharrtell avatar Jan 19 '22 12:01 bjornharrtell

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Mar 04 '23 01:03 github-actions[bot]

Commenting to avoid stale issue. Btw, as a user taking time to report bugs, I really do not like this idea of automatic issue closing, that feels like the ostrich approach to software development to me ;-P

stephanemagnenat avatar Mar 06 '23 08:03 stephanemagnenat

@stephanemagnenat but sometimes problems do go away if you just ignore them for a while. :D

bjornharrtell avatar Mar 06 '23 08:03 bjornharrtell

Seriously though, any help to improve the situation with unions would be appriecated but I still have no plans to invest time into it myself.

bjornharrtell avatar Mar 06 '23 08:03 bjornharrtell

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Sep 05 '23 20:09 github-actions[bot]

comment to avoid staling

stephanemagnenat avatar Sep 06 '23 11:09 stephanemagnenat

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Mar 06 '24 20:03 github-actions[bot]

comment to avoid staling

stephanemagnenat avatar Mar 06 '24 21:03 stephanemagnenat