performance patch for stl_vector.h

Wayne Feick waf@brunz.org
Mon Apr 7 23:31:00 GMT 2008


Damn, I'm batting 1000 today. The fix actually comes from a coworker and
has been in use for a while, so I didn't stop to look at it or think
about it. I was just trying to get it back into the code base so we
could stop patching.

Given that it's fixed correctly in the SVN tree, just ignore the
suggested patch. Sorry for the annoyance.

Wayne.


On Mon, 2008-04-07 at 15:45 -0700, Joe Buck wrote:
> On Mon, Apr 07, 2008 at 10:18:31PM +0000, Wayne Feick wrote:
> > (embarrassed blush) 
> > 
> > You are, of course, right. That should have been __n, not n. This
> > version should compile fine. Sorry for the mistake.
> > 
> > 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;
> 
> But then _M_start, _M_finish, and _M_end_of_storage will have random
> values for empty vectors, and calling member functions on an empty
> vector may crash.



More information about the Gcc-patches mailing list