Spar - inlingin

spar

Spar supports inlining for two different reasons:

An inlined method, or constructor is similar to an ordinary one, but it is declared to be a inlined with the inline keyword. For example:

class Stats {
    long sum;
    int n;

    inline Stats() { sum = 0; n = 0; }
    inline void update( int val ) {
        n++;
        sum += val;
    }
    inline float average() {
        return ((float) val)/((float) n);
    }
}

Inlined methods are very similar to ordinary methods, but the compiler is will expand them at compile time. Moreover, inlined methods can have type parameters, which is not allowed in ordinary methods.

For example, classes such as the DiagonalView and TransposeView classes shown on the Array interface page usually declare most of their methods as inlined for increased efficiency.


Last modified Sat May 13 15:50:56 2017 UT by Kees van Reeuwijk.