2 ms·
Well, of course: void constByArg(const int *x) { printf("%d\n", *x); constFunc(x); printf("%d\n", *x); } Here, the object referenced by poin
by kazinator 7y ago
Well, of course:
void constByArg(const int *x)
{
printf("%d\n", *x);
constFunc(x);
printf("%d\n", *x);
}
Here, the object referenced by pointer x is non-local, and so is constFunc.
The object could be modified in legal ways nothing to do with constFunc stripping away the qualifier.
Also, if the object is not defined const, then constFunc is allowed to do that, too.
Then the next, correct, example with a const protected local shows that two instructions are shaved off. That's a wortwhile saving that could be leveraged to get faster code.
If you're passing local variables into helper functions which are not supposed to change them, you can shave off some cycles with const.
> I mean, I removed const from the entire program
Maybe sqLite doesn't use const specifically with a view toward optimization. To see an overall performance impact, there would have to be some case in a "hot spot" of the program, where const is used with some local variables being passed into functions. (Or whatever other case we can ferret out where const happens to help.)
There are some widely applicable optimizations which scoop up all the "low hanging fruit" improvements, but after that, optimization is a game of eking out small gains with specialized cases.