removing empty AppliedClassProperties objects

This commit is contained in:
Konstantin Käfer
2014-07-01 12:50:08 +02:00
parent b9fbb4f80b
commit 475f0481b3
4 changed files with 29 additions and 3 deletions

View File

@@ -24,13 +24,29 @@ bool AppliedClassProperties::hasTransitions() const {
// Erase all items in the property list that are before a completed transition.
// Then, if the only remaining property is a Fallback value, remove it too.
void AppliedClassProperties::cleanup(timestamp now) {
// Iterate backwards, but without using the rbegin/rend interface since we need forward
// iterators to use .erase().
for (auto it = properties.end(), begin = properties.begin(); it != begin;) {
// If the property is finished, break iteration and delete all remaining items.
if ((--it)->end <= now) {
// Removes all items that precede the current iterator, but *not* the element currently
// pointed to by the iterator. This preserves the last completed transition as the
// first element in the property list.
properties.erase(begin, it);
// Also erase the pivot element if it's a fallback value. This means we can remove the
// entire applied properties object as well, because we already have the fallback
// value set as the default.
if (it->name == ClassID::Fallback) {
properties.erase(it);
}
break;
}
}
}
bool AppliedClassProperties::empty() const {
return properties.empty();
}
}