Conditional Functions #8555
Unanswered
project-x51
asked this question in
Language Ideas
Replies: 2 comments 9 replies
-
This is already possible. If the method being called is short enough, the JIT will inline it for you. The typical method (no pun intended) of doing so is: public void DoX(…)
{
if (DoThing)
DoXButForReal(…); // <- imagine that this method is hundreds of lines long
} Again, you won’t see this optimization in the compiler; the JIT will do it for you at runtime. Test it out yourself at https://sharplab.io |
Beta Was this translation helpful? Give feedback.
2 replies
-
From your example, it looks like the purpose is to avoid concatenating a string when the log isn't needed. This is the poster child for Interpolated String Handlers. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm not sure if such a feature exists already so forgive me if this is already a thing.
I propose a function that is only called if a condition is met. Such as function would be ideal for performance optimization in logging applications and possibly others. The idea is that the function definition would include a typically small set of parameters passed to it for the condition and then more parameters that are only passed to it if the condition is met.
The language would then inline the condition check and only setup the stack and call into the function if the condition was true.
So a function call like this...
Could be declared like this (as an example)
If a return value other than void was defined we could use the same idea of a default parameter. Eg bool = false.
Does this make sense?
Beta Was this translation helpful? Give feedback.
All reactions