Skip to content
Snippets Groups Projects
Commit b7b255e7 authored by Jonathan Wakely's avatar Jonathan Wakely
Browse files

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.
parent 8cbaf679
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment