Optimizing method calls
I know you are eagerly waiting to optimize some real code, but be patient as we discuss a little bit more about the theoretical side of the process. I spent a lot of time talking about the behavior of built-in data types, but I didn’t say anything about how data is passed to methods. This much shorter and more surprising section (you’ll see!) will remedy this. As I’ll be talking about speeding up method calls, I’ll also throw in a short discussion about method inlining, just for good measure. But first, parameters!
Parameter passing
In essence, Delphi knows two ways of passing parameters to a method (or a procedure, function, or anonymous method – it’s all the same). Parameters can be passed by value or by reference.
The former makes a copy of the original value and passes that copy to a method. The code inside the method can then modify its copy however it wants, without changing the original value.
The...