HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJass Automatic Inlining

09-18-2009, 10:30 PM#1
Storyyeller
I created a text display function to save typing. It looks like this
Collapse JASS:
    function cout takes string s returns nothing
        call DisplayTextToPlayer(GetLocalPlayer(),0,0,s)
    endfunction

Will this be automatically inlined? How do you tell?
09-18-2009, 10:32 PM#2
Vexorian
Yes.

...
Ok, maybe not.

It depends on whether GetLocalPlayer is in jasshelper's list of native functions that do not modify the state (it should, so if it is not it will get added)

It would be inlined because:
* It is a one-liner.
* GetLocalPlayer does not change the state.
* 0s are constants.
* All arguments are evaluated exactly once.
* All arguments are evaluated exactly in the same order as they are declared.
09-18-2009, 10:36 PM#3
Storyyeller
What about this one? c is evaluated twice, but I always use it with a constant argument anyway. Is there someway to tell the preprocessor this?
Better yet, is it possible to get StringLength(c) replaced with the appropriate integer constant each time I use it?


Collapse JASS:
    
function SubStrMatch takes string s, string c returns boolean
    return SubString(s,0,StringLength(c)) == c
endfunction

For example
Collapse JASS:
        if SubStrMatch(s,"-nuke") then
            set Nukemode=true
            call cout("Nuke mode activated")
        endif

        if SubStrMatch(s,"-timeless") then
            set Timeless=true
            call cout("Timeless mode activated")
        endif
09-18-2009, 11:05 PM#4
Vexorian
Nope,

Smarter inliner could happen every day. But StringLength(Constant_string) evaluated automatically could take a long time to happen (I'd have to implement UTF for these things)