The inline
keyword can be used before a function call or a constructor call. This allows a finer-grained control of inlining, unlike the inline access modifier.
class Main { static function mid(s1:Int, s2:Int) { return (s1 + s2) / 2; } static public function main() { var a = 1; var b = 2; var c = mid(a, b); var d = inline mid(a, b); } }
The generated JavaScript output is:
(function ($global) { "use strict"; var Test = function() { }; Test.mid = function(s1,s2) { return (s1 + s2) / 2; }; Test.main = function() { var a = 1; var b = 2; var c = Test.mid(a,b); var d = (a + b) / 2; }; Test.main(); })({});
Note that c
produces a call to the function, whereas d
does not. The usual warnings about what makes a good candidate for inlining still hold (see Inline).
An inline new
call can be used to avoid creating a local class instance. See Inline Constructors for more details.