@@ -121,23 +121,29 @@ power(expr, 10)
121121```
122122
123123Parameters of inline methods can have an ` inline ` modifier as well. This means
124- that actual arguments to these parameters will be inlined in the body of the ` inline def ` .
125- ` inline ` parameter have call semantics equivalent to by-name parameters but allows for duplication
126- of the code in the argument. It is usualy useful constant values need to be propagated to allow
127- further optimizations/reductions.
124+ that actual arguments to these parameters will be inlined in the body of the
125+ ` inline def ` . ` inline ` parameters have call semantics equivalent to by-name parameters
126+ but allow for duplication of the code in the argument. It is usualy useful constant
127+ values need to be propagated to allow further optimizations/reductions.
128128
129129The following example shows the difference in translation between by-value, by-name and ` inline `
130130parameters:
131131
132132``` scala
133- inline def sumTwice (a : Int , b : => Int , inline c : Int ) = a + a + b + b + c + c
133+ inline def specialSum (a : Int , b : => Int , inline c : Int ) =
134+ (if (a < 2 ) a else 0 ) +
135+ (if (a < 2 ) b + b else 0 ) +
136+ (if (a < 2 ) c + c else 0 )
137+ }
134138
135- sumTwice (f(), g(), h())
139+ specialSum (f(), g(), h())
136140// translates to
137141//
138142// val a = f()
139- // def b = g()
140- // a + a + b + b + h() + h()
143+ // lazy val b = g()
144+ // (if(a < 2) a else 0) +
145+ // (if(a < 2) b + b else 0) +
146+ // (if(a < 2) h() + h() else 0)
141147```
142148
143149### Relationship to @inline
0 commit comments