This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: performance patch for stl_vector.h
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Wayne Feick <waf at brunz dot org>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 7 Apr 2008 15:08:34 -0700
- Subject: Re: performance patch for stl_vector.h
- References: <1207605148.30159.25.camel@waf.brunz.org>
On Mon, Apr 07, 2008 at 09:52:28PM +0000, Wayne Feick wrote:
> 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;
This can't be right; it won't even compile. Are you sure that this
is what you intended to submit? There's no "n", no initialization for
the members.