This is picked up from http://gcc.gnu.org/ml/gcc/2007-07/msg00681.html , apologises if it has already been dealt with.
Both std::string and std::list do not compare lengths before comparing elements in operator==. In std::string this increases the chances of quitting early and produces a small improvement even for equal length strings. For std::list this produces a much larger gain. I believe the operator== for list should simply be replaced implementation used for all the other containers: { return (__x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin())); } Which is efficent as list has a O(1) size. -- Summary: Inefficent operator== in std::string and std::list Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: chris at bubblescope dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32907