libstdc++: Fix code size regressions in std::vector [PR110060]
My r14-1452-gfb409a15d9babc change to add optimization hints to std::vector causes regressions because it makes std::vector::size() and std::vector::capacity() too big to inline. That's the opposite of what I wanted, so revert the changes to those functions. To achieve the original aim of optimizing vec.assign(vec.size(), x) we can add a local optimization hint to _M_fill_assign, so that it doesn't affect all other uses of size() and capacity(). Additionally, add the same hint to the _M_assign_aux overload for forward iterators and add that to the testcase. It would be nice to similarly optimize: if (vec1.size() == vec2.size()) vec1 = vec2; but adding hints to operator=(const vector&) doesn't help. Presumably the relationships between the two sizes and two capacities are too complex to track effectively. libstdc++-v3/ChangeLog: PR libstdc++/110060 * include/bits/stl_vector.h (_Vector_base::_M_invariant): Remove. (vector::size, vector::capacity): Remove calls to _M_invariant. * include/bits/vector.tcc (vector::_M_fill_assign): Add optimization hint to reallocating path. (vector::_M_assign_aux(FwdIter, FwdIter, forward_iterator_tag)): Likewise. * testsuite/23_containers/vector/capacity/invariant.cc: Moved to... * testsuite/23_containers/vector/modifiers/assign/no_realloc.cc: ...here. Check assign(FwdIter, FwdIter) too. * testsuite/23_containers/vector/types/1.cc: Revert addition of -Wno-stringop-overread option.
Showing
- libstdc++-v3/include/bits/stl_vector.h 1 addition, 22 deletionslibstdc++-v3/include/bits/stl_vector.h
- libstdc++-v3/include/bits/vector.tcc 12 additions, 5 deletionslibstdc++-v3/include/bits/vector.tcc
- libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/no_realloc.cc 6 additions, 0 deletions...suite/23_containers/vector/modifiers/assign/no_realloc.cc
- libstdc++-v3/testsuite/23_containers/vector/types/1.cc 1 addition, 1 deletionlibstdc++-v3/testsuite/23_containers/vector/types/1.cc
Loading
Please register or sign in to comment