vector::clear calls erase(begin(), end()), which has an unnecessary call to memmove, in addition to a function call overhead. The fix results in a 2-instruction clear for simple types.
Compiling the following (-O2 -save-temps) shows the difference: #include <vector> using std::vector; int main() { vector<int> v; asm("#start1"); v.clear(); asm("#end1"); asm("#start2"); v.erase(v.begin(), v.end()); asm("#end2"); } This was a notable performance difference between libstdc++ stl and stlport I found in profiling a large application. -- Summary: vector::clear should be manually inlined Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: tkho at ucla dot edu CC: dank at kegel dot com,gcc-bugs at gcc dot gnu dot org GCC host triplet: i686-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23425