Improve array KVO performance a bit
This commit is contained in:
parent
c3649fbd17
commit
eeb2ddd794
|
@ -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;
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue