This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/79206] New: string_view operator== could do an early exit if sizes differ
- From: "kalven at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 24 Jan 2017 04:22:51 +0000
- Subject: [Bug libstdc++/79206] New: string_view operator== could do an early exit if sizes differ
- Auto-submitted: auto-generated
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.