4 ms·
Extending the array is not needed: you can store the last element in a variable, then overwrite the last element with the searched value, do the search then res
by renox 7y ago
Extending the array is not needed: you can store the last element in a variable, then overwrite the last element with the searched value, do the search then restore the last element.
I remember a talk from Alexei Andrulescu(sp?) where he talk about this optimisation but I don't remember if there was benchmarks.
- mkl 7y agoThat's clever, but it still requires writing to the array, which is dodgy in many circumstances; other threads may be using it, so the search function is likely to be given only read-only access.