diff --git a/src/buffer/katetextline.h b/src/buffer/katetextline.h --- a/src/buffer/katetextline.h +++ b/src/buffer/katetextline.h @@ -412,20 +412,7 @@ * @param pos position of attribute requested * @return value of attribute */ - 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; - } - } - - return 0; - } + short attribute(int pos) const; /** * set hl continue flag diff --git a/src/buffer/katetextline.cpp b/src/buffer/katetextline.cpp --- a/src/buffer/katetextline.cpp +++ b/src/buffer/katetextline.cpp @@ -205,4 +205,17 @@ m_attributesList.append(attribute); } +short TextLineData::attribute(int pos) const +{ + auto first = std::lower_bound(m_attributesList.cbegin(), m_attributesList.cend(), pos, + [](const Attribute &x, const int &p) { + return x.offset + x.length <= p; + }); + if (first != m_attributesList.cend() && (*first).offset <= pos && pos < ((*first).offset + (*first).length)) + { + return (*first).attributeValue; + } + return 0; +} + }