305305so long as the ` Type ` of the rebound variable (` x ` , above) does not change.
306306
307307On the other hand, the above code for mutable containers like ` Array ` , ` MArray `
308- or ` SizedArray ` is * not* very efficient. Mutable containers in Julia 0.5 must
308+ or ` SizedArray ` is * not* very efficient. Mutable containers must
309309be * allocated* and later * garbage collected* , and for small, fixed-size arrays
310310this can be a leading contribution to the cost. In the above code, a new array
311311will be instantiated and allocated on each iteration of the loop. In order to
@@ -315,17 +315,12 @@ apply mutating functions to it:
315315function average_position (positions:: Vector{SVector{3,Float64}} )
316316 x = zeros (MVector{3 ,Float64})
317317 for pos ∈ positions
318- # Take advantage of Julia 0.5 broadcast fusion
319- x .= (+ ). (x, pos) # same as broadcast!(+, x, x, positions[i])
318+ x .+ = pos
320319 end
321- x .= ( / ) . (x, length (positions) )
320+ x ./= length (positions)
322321 return x
323322end
324323```
325- Keep in mind that Julia 0.5 does not fuse calls to ` .+ ` , etc (or ` .+= ` etc),
326- however the ` .= ` and ` (+).() ` syntaxes are fused into a single, efficient call
327- to ` broadcast! ` . The simpler syntax ` x .+= pos ` is expected to be non-allocating
328- (and therefore faster) in Julia 0.6.
329324
330325The functions ` setindex ` , ` push ` , ` pop ` , ` pushfirst ` , ` popfirst ` , ` insert ` and ` deleteat `
331326are provided for performing certain specific operations on static arrays, in
0 commit comments