Is this in a performance critical section of your code? Did you profile it? If not, just leave it. If it is, it will be reasonably tricky to get fast because operating on a bunch of different things is slow. Except if it is just a small union of different types, then you should encode that. Reference in How to tell if a type is an efficient small type union? might help.
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Type Stability: Collections of Abstract Types | 5 | 991 | April 4, 2021 | |
| List of elements with unknown type, is it bad? | 3 | 1475 | January 25, 2021 | |
| Container of heterogeneous types | 19 | 1783 | March 23, 2019 | |
| Help to avoid a type-instability | 13 | 1275 | February 3, 2020 | |
| Type-stable broadcasting involving nested array | 9 | 358 | February 28, 2023 |