This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

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;



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