This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: performance patch for stl_vector.h


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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]