Improve array KVO performance a bit

This commit is contained in:
Thomas Goyne 2015-09-02 11:04:01 -07:00
parent c3649fbd17
commit eeb2ddd794
3 changed files with 11 additions and 8 deletions

View File

@ -91,6 +91,15 @@ void IndexSet::insert_at(size_t index)
do_add(pos, index);
}
void IndexSet::add_shifted(size_t index)
{
auto it = m_ranges.begin();
for (auto end = m_ranges.end(); it != end && it->first <= index; ++it) {
index += it->second - it->first;
}
do_add(it, index);
}
size_t IndexSet::iterator::operator*() const
{
return m_data->first + m_offset;

View File

@ -48,6 +48,7 @@ public:
void set(size_t len);
// Insert an index at the given position, shifting existing indexes back
void insert_at(size_t index);
void add_shifted(size_t index);
private:
using Range = std::pair<size_t, size_t>;

View File

@ -193,14 +193,7 @@ public:
}
else if (o->kind == kind) {
if (kind == ColumnInfo::Kind::Remove) {
// Shift the index to compensate for already-removed indices
for (auto i : o->indices) {
if (i <= index)
++index;
else
break;
}
o->indices.add(index);
o->indices.add_shifted(index);
}
else if (kind == ColumnInfo::Kind::Insert) {
o->indices.insert_at(index);