Don't immediately delete unused extradata entries
Instead, count how many consecutive times the entry has been found to be unused and delete it once that count exceeds a limit. This will prevent excessive reallocating of extradata ID's in applications like folding.
This commit is contained in:
parent
58d6ab520b
commit
b41f6bde71
3 changed files with 10 additions and 3 deletions
|
@ -236,7 +236,7 @@ uint32_t AssFile::AddExtradata(std::string const& key, std::string const& value)
|
|||
return data.id;
|
||||
}
|
||||
}
|
||||
Extradata.push_back(ExtradataEntry{next_extradata_id, key, value});
|
||||
Extradata.push_back(ExtradataEntry{next_extradata_id, 0, key, value});
|
||||
return next_extradata_id++; // return old value, then post-increment
|
||||
}
|
||||
|
||||
|
@ -334,10 +334,16 @@ void AssFile::CleanExtradata() {
|
|||
}
|
||||
}
|
||||
|
||||
for (ExtradataEntry &e : Extradata) {
|
||||
if (ids_used.count(e.id))
|
||||
e.expiration_counter = 0;
|
||||
else
|
||||
e.expiration_counter++;
|
||||
}
|
||||
if (ids_used.size() != Extradata.size()) {
|
||||
// Erase all no-longer-used extradata entries
|
||||
Extradata.erase(std::remove_if(begin(Extradata), end(Extradata), [&](ExtradataEntry const& e) {
|
||||
return !ids_used.count(e.id);
|
||||
return e.expiration_counter >= 10;
|
||||
}), end(Extradata));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ using EntryList = typename boost::intrusive::make_list<T, boost::intrusive::cons
|
|||
|
||||
struct ExtradataEntry {
|
||||
uint32_t id;
|
||||
int expiration_counter;
|
||||
std::string key;
|
||||
std::string value;
|
||||
};
|
||||
|
|
|
@ -219,7 +219,7 @@ void AssParser::ParseExtradataLine(std::string const &data) {
|
|||
|
||||
// ensure next_extradata_id is always at least 1 more than the largest existing id
|
||||
target->next_extradata_id = std::max(id+1, target->next_extradata_id);
|
||||
target->Extradata.push_back(ExtradataEntry{id, std::move(key), std::move(value)});
|
||||
target->Extradata.push_back(ExtradataEntry{id, 0, std::move(key), std::move(value)});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue