If it is only given a value at the instantiation of the class, can't you mark it as const and initialise it in the initialiser list of the constructor?
The object is populated with data from a file; n varies with the size of the file; but once loaded doesn't change.
n is then used as the bound in literally dozens of loops; and the code is indirecting for every iteration of every loop, rather than just loading the value into a register and comparing.
I can work around it by having
1 2 3 4 5 6 7 8 9 10
class::method ( ... ) {
constint nn = n;
...
for( int i=0; i < nn; ++ i ) {
...
}
...
}
But as there are actually half a dozen of these limits for various loops I end up with something like this at the top of many methods: