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

libstdc++: Express std::vector's size() <= capacity() invariant in code

This adds optimizer hints so that GCC knows that size() <= capacity() is
always true. This allows the compiler to optimize away re-allocating
paths when assigning new values to the vector without resizing it, e.g.,
vec.assign(vec.size(), new_val).

libstdc++-v3/ChangeLog:

	* include/bits/stl_vector.h (_Vector_base::_M_invariant()): New
	function.
	(vector::size(), vector::capacity()): Call _M_invariant().
	* testsuite/23_containers/vector/capacity/invariant.cc: New test.
	* testsuite/23_containers/vector/types/1.cc: Add suppression for
	false positive warning (PR110060).
parent a239a350
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