Skip to main content
typo and grammar fixes, made my fist point clearer
Source Link

First of all I would notavoid to allocate memory for variables each run (I know this looks C style bit it isn't you do not want to allocate memory in loops), since allocating is a heavy operation.

Then do not call u.size() in the for-loop declaration. One jumping to aIt will be called every loop otherwise. Every function and jumping back including all overheadcall less each roundthat you call in a loop is a good win for performance.

Next everything Nemanja Boric said in the other answer.

AnsAnd since the variable u is passed as copy, you can use it as return value and operate directly on it.

wstring wstringToLower(wstring u) { int size = u.size(); for (int i = 0; i < size; ++i) { u[i] = charCodeToLower(static_cast<int>(u[i])); } return u; } 

Conclusion: Basically avoid to allocate memory or calling functions in loops. Do just as much as you really have to.

First of all I would not allocate memory for variables each run (I know this looks C style bit it isn't you do not want to allocate memory in loops)

Then do not call u.size() in the for declaration. One jumping to a function and jumping back including all overhead less each round.

Next everything Nemanja Boric said in the other answer.

Ans since u is passed as copy, you can use it as return value and operate directly on it.

wstring wstringToLower(wstring u) { int size = u.size(); for (int i = 0; i < size; ++i) { u[i] = charCodeToLower(static_cast<int>(u[i])); } return u; } 

Conclusion: Basically avoid to allocate memory or calling functions in loops. Do just as much as you really have to.

First of all I would avoid to allocate memory for variables each run, since allocating is a heavy operation.

Then do not call u.size() in the for-loop declaration. It will be called every loop otherwise. Every function call less that you call in a loop is a good win for performance.

Next everything Nemanja Boric said in the other answer.

And since the variable u is passed as copy, you can use it as return value and operate directly on it.

wstring wstringToLower(wstring u) { int size = u.size(); for (int i = 0; i < size; ++i) { u[i] = charCodeToLower(static_cast<int>(u[i])); } return u; } 

Conclusion: Basically avoid to allocate memory or calling functions in loops. Do just as much as you really have to.

Source Link

First of all I would not allocate memory for variables each run (I know this looks C style bit it isn't you do not want to allocate memory in loops)

Then do not call u.size() in the for declaration. One jumping to a function and jumping back including all overhead less each round.

Next everything Nemanja Boric said in the other answer.

Ans since u is passed as copy, you can use it as return value and operate directly on it.

wstring wstringToLower(wstring u) { int size = u.size(); for (int i = 0; i < size; ++i) { u[i] = charCodeToLower(static_cast<int>(u[i])); } return u; } 

Conclusion: Basically avoid to allocate memory or calling functions in loops. Do just as much as you really have to.