diff --git a/src/buffer/katetextline.h b/src/buffer/katetextline.h --- a/src/buffer/katetextline.h +++ b/src/buffer/katetextline.h @@ -414,13 +414,13 @@ */ short attribute(int pos) const { - for (int i = 0; i < m_attributesList.size(); ++i) { - if (pos >= m_attributesList[i].offset && pos < (m_attributesList[i].offset + m_attributesList[i].length)) { - return m_attributesList[i].attributeValue; - } - - if (pos < m_attributesList[i].offset) { - break; + // find the lowest item that has offset >= pos in a binary search + auto first = std::lower_bound(m_attributesList.cbegin(), m_attributesList.cend(), + pos, [](const Attribute &x, const Attribute &y) + {return x.offset < y.offset;} ); + if (first != m_attributesList.cend()) { + if (pos < ((*first).offset + (*first).length)) { + return (*first).attributeValue; } }