Const Function Parameters?
Felix Nawothnig
felix.nawothnig at t-online.de
Tue Jul 26 18:25:11 CDT 2005
Michael Carlson wrote:
> I've also found that marking a couple of parameters of that function
> const (that I believe should be marked const anyways), CPU usage in
> that function drops measurably with oprofile. As far as I know,
> parameters that aren't modified in a function should be marked const
> anyways, to send the right hint to the compiler. Since it actually
> turns out to be faster too, it seems worth it to me.
>
> -static void convert_5x5_asis(int width, int height,
> - const void* srcbits, int srclinebytes,
> - void* dstbits, int dstlinebytes)
> +static void convert_5x5_asis(const int width, const int height,
> + const void* srcbits, const int srclinebytes,
> + void* dstbits, const int dstlinebytes)
There is no need to make anything except the pointers const - I don't
think I've ever seen that in real world code. In theory this would give
the compiler slightly more information... but if the optimizer is unable
to figure out that the parameter is never used as an lvalue by himself
it sucks so badly that it probably won't do much better with that hints
anyway. :-)
Constifying the pointers is fine ofcourse (but rather because it helps
finding bugs than for those 1.5% performance improvements.
Felix
More information about the wine-devel
mailing list