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.