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

std::string::operator==/!= optimization


Looking at the std::string comparison operators, they all seem to be
using std::string::compare directly even in cases where the string
lengths must match. Comparing the string lengths before the
std::string::compare call in std::string::operator==/!= would avoid
doing a byte-for-byte comparison in most cases where unequal strings
are compared.

A quick glance at the object code shows that the new conditional
replaces the std::min in std::string::compare in addition to reducing
the code size slightly, when compiled with -O2.

Or is there some specific reasons why this isn't done?

Jari Sundell


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