Rework Buffer::distance implementation

This commit is contained in:
Maxime Coste 2015-11-04 00:37:39 +00:00
parent e8239feddf
commit 6273aa9443

View File

@ -43,16 +43,13 @@ inline ByteCount Buffer::distance(ByteCoord begin, ByteCoord end) const
{ {
if (begin > end) if (begin > end)
return -distance(end, begin); return -distance(end, begin);
ByteCount res = 0; if (begin.line == end.line)
for (LineCount l = begin.line; l <= end.line; ++l) return end.column - begin.column;
{
ByteCount len = m_lines[l].length(); ByteCount res = m_lines[begin.line].length() - begin.column;
res += len; for (LineCount l = begin.line+1; l < end.line; ++l)
if (l == begin.line) res += m_lines[l].length();
res -= begin.column; res += end.column;
if (l == end.line)
res -= len - end.column;
}
return res; return res;
} }