tooltiperror
Super Moderator
- Reaction score
- 231
Why should I make a function constant? What will it do?
Constant functions may not call non-constant functions and they may not manipulate any element that cannot be a constant (arrays and code).
Both regular functions and constant functions are inlined if they follow these rules:
* The function is a one-liner
* If the function is called by call the function's contents must begin with a variable assignment (=) or a function call or be a return of a single function.
* If the inlined function is an assigment, it should not assign one of its arguments (input).
* Every argument must be evaluated once and only once by the function, in the same order as they appear in the arguments list.
* If the function contains function calls, they should all be evaluated after the arguments UNLESS the function is marked as non-state changing, at the moment some very few native functions and also return bug exploiters are considered as non-state changing.
So really, constant functions are pretty deprecated.
Constants that aren't inlined are exactly the same speed as their non-constant cousins
So, which parts apply to vanilla JASS? (If you hadn't noticed, ToolTipError is on a Mac and doesn't care to use vJASS.)From my guide-
AFAIK, there's no inlining with the stock WE compiler, so does that mean there is no difference made by declaring a constant function?Constants that aren't inlined are exactly the same speed as their non-constant cousins
Doesn't stop me from explaining the theory.If you write a constant function, it should
static if LIBRARY_TABLE then
call BJDebugMsg("You have the library table in the map.")
endif