-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Declare ImVec2 and ImVec4 constructors as constexpr #4995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The change in syntax from assignments to initializations is because assignment statements aren't supported in |
Would it be worth changing the example constructors in |
Maybe. I think a lot of users would feed |
Can you clarify which compiler/settings and which sorts of constructs it would make a difference? (In my tests with VS15 both debug and release exe for example_win32_directx11.exe were identical.) EDIT To clarify I am not pushing against this at all, but I want to really understand the effects it has on code generation. |
I made some tests, with e.g. a large table initialized with ImVec2() entries and could notice a difference. What was your use case? That's a good enough reason for merging so I'll merge either way, but curious to understand this well. |
…tType_Char to ImGuiInputEventType_Text for consistency with event structure.
We have an Combined with the rule that |
…putEventType_Char to ImGuiInputEventType_Text for consistency with event structure.
An aside for both @Myriachan and @ocornut ... it's currently a little confusing as to whether trivial/defaulted/empty ctors are a good thing.
Done like this, the compiler will likely inline that constructor into every translation unit where it's needed, and I chose string because it's a sneakily complex constructor: https://gcc.godbolt.org/z/jWcrxaonG vs https://gcc.godbolt.org/z/sf8Ph3hG7 All too often we forget this applies for a defaulted/empty constructor too: https://gcc.godbolt.org/z/MMc8vYoeT (compare f1 vs f2 implementation). Here you're trading code size for branch avoidance, and you're really in amongst the weeds of compiler optimization flags and behaviors. Are they building -Os or -On? Whole program optimization? Is this a hot- or cold-path branch? That's a really, really hard generalized library solve and constexpr - or ideally, '20s consteval - is a great alternative. |
This change actually lets us save 400 KB of machine code in our .exe file because a bunch of Dear ImgUi-related calculations can be moved from runtime to compile-time.
Your guidelines document says that C++11 isn't required, but there are recent commits that seem to say that pre-C++11 isn't being supported anymore, so I assume that the guidelines are out of date on this.