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++/79206] New: string_view operator== could do an early exit if sizes differ


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79206

            Bug ID: 79206
           Summary: string_view operator== could do an early exit if sizes
                    differ
           Product: gcc
           Version: 6.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kalven at gmail dot com
  Target Milestone: ---

operator== for string_view has this implementation:

  template<typename _CharT, typename _Traits>
    inline bool
    operator==(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) == 0; }

If __x and __y differ in lengths, this will start a pointless comparison of up
to min(__x.size(), __y.size()) elements. This can be avoided with an early
exit.

FWIW, libc++ has this optmization.

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