Clear containers instead of individual erases

This has O(n) runtime instead of O(n log n).
This commit is contained in:
Andrew Gaul 2019-01-27 15:46:43 -08:00
parent c04e8e7a9d
commit 4d0bef1e90
3 changed files with 14 additions and 6 deletions

View File

@ -213,9 +213,10 @@ void StatCache::Clear()
{
AutoLock lock(&StatCache::stat_cache_lock);
for(stat_cache_t::iterator iter = stat_cache.begin(); iter != stat_cache.end(); stat_cache.erase(iter++)){
for(stat_cache_t::iterator iter = stat_cache.begin(); iter != stat_cache.end(); ++iter){
delete (*iter).second;
}
stat_cache.clear();
S3FS_MALLOCTRIM(0);
}

View File

@ -3958,21 +3958,24 @@ S3fsMultiCurl::~S3fsMultiCurl()
bool S3fsMultiCurl::ClearEx(bool is_all)
{
s3fscurlmap_t::iterator iter;
for(iter = cMap_req.begin(); iter != cMap_req.end(); cMap_req.erase(iter++)){
for(iter = cMap_req.begin(); iter != cMap_req.end(); ++iter){
S3fsCurl* s3fscurl = (*iter).second;
if(s3fscurl){
s3fscurl->DestroyCurlHandle();
delete s3fscurl; // with destroy curl handle.
}
}
cMap_req.clear();
if(is_all){
for(iter = cMap_all.begin(); iter != cMap_all.end(); cMap_all.erase(iter++)){
for(iter = cMap_all.begin(); iter != cMap_all.end(); ++iter){
S3fsCurl* s3fscurl = (*iter).second;
s3fscurl->DestroyCurlHandle();
delete s3fscurl;
}
cMap_all.clear();
}
S3FS_MALLOCTRIM(0);
return true;
@ -4078,7 +4081,7 @@ int S3fsMultiCurl::MultiPerform()
int S3fsMultiCurl::MultiRead()
{
for(s3fscurlmap_t::iterator iter = cMap_req.begin(); iter != cMap_req.end(); cMap_req.erase(iter++)) {
for(s3fscurlmap_t::iterator iter = cMap_req.begin(); iter != cMap_req.end(); ++iter) {
S3fsCurl* s3fscurl = (*iter).second;
bool isRetry = false;
@ -4139,6 +4142,8 @@ int S3fsMultiCurl::MultiRead()
}
}
}
cMap_req.clear();
return 0;
}
@ -4155,12 +4160,13 @@ int S3fsMultiCurl::Request()
// set curl handle to multi handle
int result;
s3fscurlmap_t::iterator iter;
for(iter = cMap_all.begin(); iter != cMap_all.end(); cMap_all.erase(iter++)){
for(iter = cMap_all.begin(); iter != cMap_all.end(); ++iter){
CURL* hCurl = (*iter).first;
S3fsCurl* s3fscurl = (*iter).second;
cMap_req[hCurl] = s3fscurl;
}
cMap_all.clear();
// Send multi request.
if(0 != (result = MultiPerform())){

View File

@ -2884,9 +2884,10 @@ static int remote_mountpath_exists(const char* path)
static void free_xattrs(xattrs_t& xattrs)
{
for(xattrs_t::iterator iter = xattrs.begin(); iter != xattrs.end(); xattrs.erase(iter++)){
for(xattrs_t::iterator iter = xattrs.begin(); iter != xattrs.end(); ++iter){
delete iter->second;
}
xattrs.clear();
}
static bool parse_xattr_keyval(const std::string& xattrpair, string& key, PXATTRVAL& pval)