← Back to team overview

kicad-developers team mailing list archive

needless copying to the stack

 


Regularly there is code committed which generates needless copying of an
array to the stack:


somefunction()
{

    GRTextHorizJustifyType hjustify[3] = {
        GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_CENTER,
        GR_TEXT_HJUSTIFY_RIGHT
    };


the above actually copies the array to the stack, and this is needless code
for a fixed data array.


For fixed data, better to use static const, since this will omit the copying
machine code.


    static const GRTextHorizJustifyType hjustify[3] = {
        GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_CENTER,
        GR_TEXT_HJUSTIFY_RIGHT
    };


}