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.