Speed up expand_unprintable by avoiding BufferIterator
Using BufferIterator adds overhead, but we know that DisplayAtoms cannot span multiple buffer lines and hence we can directly iterate using char pointers.
This commit is contained in:
parent
20278ed52b
commit
f3201cb956
|
@ -1351,22 +1351,24 @@ void expand_unprintable(HighlightContext context, DisplayBuffer& display_buffer,
|
||||||
if (atom_it->type() != DisplayAtom::Range)
|
if (atom_it->type() != DisplayAtom::Range)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (auto it = get_iterator(buffer, atom_it->begin()),
|
auto begin = atom_it->begin();
|
||||||
end = get_iterator(buffer, atom_it->end()); it < end;)
|
auto line_data = buffer[begin.line].data();
|
||||||
|
for (auto it = line_data + begin.column, end = line_data + atom_it->end().column; it < end;)
|
||||||
{
|
{
|
||||||
auto coord = it.coord();
|
auto next = it;
|
||||||
Codepoint cp = utf8::read_codepoint(it, end);
|
Codepoint cp = utf8::read_codepoint(next, end);
|
||||||
if (cp != '\n' and (cp < ' ' or cp > '~') and not iswprint((wchar_t)cp))
|
if (cp != '\n' and (cp < ' ' or cp > '~') and not iswprint((wchar_t)cp))
|
||||||
{
|
{
|
||||||
if (coord != atom_it->begin())
|
if (ByteCount pos(it - line_data); pos != begin.column)
|
||||||
atom_it = ++line.split(atom_it, coord);
|
atom_it = ++line.split(atom_it, {begin.line, pos});
|
||||||
if (it.coord() < atom_it->end())
|
if (ByteCount pos(next - line_data); pos < atom_it->end().column)
|
||||||
atom_it = line.split(atom_it, it.coord());
|
atom_it = line.split(atom_it, {begin.line, pos});
|
||||||
|
|
||||||
atom_it->replace("<EFBFBD>");
|
atom_it->replace("<EFBFBD>");
|
||||||
atom_it->face = error;
|
atom_it->face = error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
it = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user