On 03/27/2011 04:52 PM, Joshua Beck wrote:
> On a side note, you could rearrange this loop to use less multiplications:
> +    for(i = 0; i<  24; i++)
> +    {
> +        int sixi = 6 * i;
> +        vertices[sixi    ] *= width;
> +        vertices[sixi + 1] *= height;
> +        vertices[sixi + 2] *= depth;
> +    }
> 
> Or even better:
> +    for(i = 0; i<  144; i+=4)
> +    {
> +        vertices[i  ] *= width;
> +        vertices[++i] *= height;
> +        vertices[++i] *= depth;
> +    }
> 
> 

I find that the second variant you proposed hinders comprehension of the
loop, as Dmitry's responses imply. While the first variant is perfectly
fine, I wanted to point out that in terms of code generation with
optimization enabled, the original and your variants are identical, so
your suggestions don't have any impact on runtime performance of the loop.

Attachment: signature.asc
Description: OpenPGP digital signature



Reply via email to