Description
Environment
Problem
Replacing GenericVector
with std::vector
has resulted in a small execution time performance decrease (about 4% on my simple test). I am not sure whether some other bugs have been introduced this way.
Most of the issues I could see are from changing generic_vector.init_to_size(n, x);
directly into vector.resize(n, x);
. It is because init_to_size()
not only resizes the vector but also resets all of its values (not only the new ones).
Suggested Fix
Recheck the logic and update GenericVector
's changed lines:
gv.init_to_size(n, x) and gv.resize(n, x) should become:
v.clear();
v.resize(n, x);
gv.truncate(n) (other than truncate(0) which is just v.clear()) should become:
if (n < v.size()) {
v.resize(n);
}
gv.resize_no_init(n) (I think this one was ok):
v.resize(n);
I have added an example in comments of a commit where the first performance hit was noted .
As far as I could see the code affected is within commit range 92b6c652..65d882f9. I might be able to provide a PR but this could take some time.