[Bug libstdc++/79206] New: string_view operator== could do an early exit if sizes differ
kalven at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Jan 24 04:23:00 GMT 2017
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.
More information about the Gcc-bugs
mailing list