c++ - What is more efficient: vector.clear() or if(vector.empty()) clear();? -
as subject states.. version more efficient , why?
std::vector a; .. a.clear();
or
std::vector a; .. if(!a.empty()) a.clear();
an empty vector valid vector. operation
a.clear();
is valid on empty vector.
test emptiness before clear unnecessary , time consuming, first 1 more efficient.
Comments
Post a Comment