This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
performance patch for stl_vector.h
- From: Wayne Feick <waf at brunz dot org>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 07 Apr 2008 21:52:28 +0000
- Subject: performance patch for stl_vector.h
We've found that the following patch to avoid allocating storage for 0
length vectors is a significant performance win in our product. I'd like
to get it folded back into libstdc++.
Thanks,
Wayne.
Index: include/bits/stl_vector.h
===================================================================
--- include/bits/stl_vector.h (revision 133987)
+++ include/bits/stl_vector.h (working copy)
@@ -114,6 +114,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GL
_Vector_base(size_t __n, const allocator_type& __a)
: _M_impl(__a)
{
+ if (n == 0) return;
this->_M_impl._M_start = this->_M_allocate(__n);
this->_M_impl._M_finish = this->_M_impl._M_start;
this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;