diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-08-23 08:42:00 +0700 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-08-23 08:42:00 +0700 |
| commit | 3efc406d571d651ed44b751eb798cc79a990c614 (patch) | |
| tree | ca596dd4da396c070f3bf4e52568eab29ac895c2 /src | |
| parent | 6176a19520515cbf3ad00efc558fb459547f029b (diff) | |
Optimize DisplayBuffer::optimize()
Previous implementation was erasing in the middle of the atoms
vector each time two atoms were merged, leading to a move of
all following atoms.
Diffstat (limited to 'src')
| -rw-r--r-- | src/display_buffer.cc | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/display_buffer.cc b/src/display_buffer.cc index d9771327..3694839a 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -136,37 +136,31 @@ void DisplayLine::optimize() return; auto atom_it = m_atoms.begin(); - auto next_atom_it = atom_it + 1; - while (next_atom_it != m_atoms.end()) + for (auto next_it = atom_it + 1; next_it != m_atoms.end(); ++next_it) { auto& atom = *atom_it; - auto& next_atom = *next_atom_it; - bool merged = false; + auto& next = *next_it; - if (atom.face == next_atom.face and - atom.type() == next_atom.type()) + const auto type = atom.type(); + if (type == next.type() and atom.face == next.face) { - auto type = atom.type(); - if ((type == DisplayAtom::Range or - type == DisplayAtom::ReplacedRange) and - next_atom.begin() == atom.end()) - { - atom.m_range.end = next_atom.end(); - if (type == DisplayAtom::ReplacedRange) - atom.m_text += next_atom.m_text; - merged = true; - } if (type == DisplayAtom::Text) + atom.m_text += next.m_text; + else if ((type == DisplayAtom::Range or + type == DisplayAtom::ReplacedRange) and + next.begin() == atom.end()) { - atom.m_text += next_atom.m_text; - merged = true; + atom.m_range.end = next.end(); + if (type == DisplayAtom::ReplacedRange) + atom.m_text += next.m_text; } + else + *++atom_it = std::move(*next_it); } - if (merged) - next_atom_it = m_atoms.erase(next_atom_it); else - atom_it = next_atom_it++; + *++atom_it = std::move(*next_it); } + m_atoms.erase(atom_it+1, m_atoms.end()); } ColumnCount DisplayLine::length() const |
