This is the mail archive of the gcc-bugs@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]

[Bug libstdc++/28765] New: __gnu_cxx::__vstring::clear() is slow


Compile this code with -O2:

#include <ext/vstring.h>

void foo(__gnu_cxx::__vstring s)
{
  s.clear();
}

Look at the resulting assembler code.  Do not show it to small children.  It is
too scary.

With this simple patch:

--- include/ext/sso_string_base.h       (revision 116231)
+++ include/ext/sso_string_base.h       (working copy)
@@ -540,7 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
     }

   template<typename _CharT, typename _Traits, typename _Alloc>
-    void
+    inline void
     __sso_string_base<_CharT, _Traits, _Alloc>::
     _M_erase(size_type __pos, size_type __n)
     {

I get this code:

        pushl   %ebp
.LCFI0:
        movl    %esp, %ebp
.LCFI1:
        movl    8(%ebp), %eax
        movl    $0, 4(%eax)
        movl    (%eax), %eax
        movb    $0, (%eax)
        popl    %ebp
        ret

Much nicer.

I think this would be an appropriate fix, as _M_erase is not large.  Another
possible fix would be to change clear to call _M_set_length(0).


-- 
           Summary: __gnu_cxx::__vstring::clear() is slow
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at airs dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28765


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