boost-ext/reflect

enum_name - runtime full array processing at every call

Closed this issue · 1 comments

I must say can not understand Your original idea behind enum_name implementation, or it is just some unfinished not fully implemented idea ..

obraz

At every call at runtime with runtime variable of some enumeration, code is filling at runtime temporary local array of enum names, just to return enum name from one record of array ...
It looks like You wanted to make this array to be filled at compile time but this never was finished ..

Can You explain what's going on here ?

That was constexpr implementation, wasn't considering run-time evaluation.

Fixed now by 0f80f4f.

The idea described here - https://godbolt.org/z/vTMej7GaM producing

.LC0:
        .string "constexpr std::string_view detail::function_name() [with auto V = A; std::string_view = std::basic_string_view<char>]"
.LC1:
        .string "constexpr std::string_view detail::function_name() [with auto V = B; std::string_view = std::basic_string_view<char>]"
foo(E):
        movq    $.LC0+66, -32(%rsp)
        movl    %edi, %edi
        movq    $1, -24(%rsp)
        salq    $4, %rdi
        movq    $.LC1+66, -16(%rsp)
        movq    -32(%rsp,%rdi), %rdx
        movq    $1, -40(%rsp)
        movq    -40(%rsp,%rdi), %rax
        ret

Note that this implementation is generating jump table. To get faster perf it should consider how sparse the elements are do either if/else switch jump table or binary_search, which hasnt' been done yet.

In constexpr context that doesn't matter as long as the ocmpilation is faster;

On the compilation times front. Expecting a bit of a slow down, but not too much.