"Pass by reference"
Status: Inactive
Brought to you by:
robgreayer
Okay, obviously not a real-thing, but this relates to inlined functions. Basically it would be cool if we could provide a hint specifying function parameters which should /not/ be copied when inlined. For example, this function:
string doSomething(string msg) {
return msg;
}
myMsg = doSomething(myMsg);
Ignoring optimisation could end up being inlined like:
string msg0 = myMsg;
string ret0 = msg0;
myMsg = ret0;
Obviously this is only an example case to illustrate the point, but it's a bit wasteful. If however we were able to specify that it's okay to just pass in the raw value, then the need for copying in this way could be removed.
Are you suggesting that the sequence:
string msg0 = myMsg;
string ret0 = msg0;
string myMsg = ret0;
actually copies the strings, rather than references to the strings? I don't believe this is the case, as strings in LSL are immutable.
I'm just trying to illustrate this with a trivial case. A more involved one might be:
string msg0 = msg;
msg0 = llDeleteSubString(msg0, 0, 0);
msg = ms0;
Immediately before the line "msg = msg0;" there are now two-strings, almost the same size, whereas ideally there'd only be one, with the originally value of msg becoming orphaned for garbage-collection.
Thinking about it it may be better overall if the compiler was able to detect that a variable is being assigned a value from a function to which it was passed as an argument, thus meaning there is no need for a copy to be created as any change to the variable itself won't matter. However, pass-by-reference may be more useful in more complex cases, for example if I wanted to have an inline function capable of directly modifying any global variable I pass to it, for example:
// pragma inline
doSomethingToList(list l) {
// Does something to list
}
doSomethingToList(myList);
doSomethingToList(myOtherList);