summaryrefslogtreecommitdiff
path: root/src/selection.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-05-29 05:48:40 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-05-29 05:48:40 +0100
commit49ab0c101a1cef1a5c57e4e2dec3160309510d7a (patch)
tree880b5319351765cf6898574fea6346ee78508673 /src/selection.hh
parente1c9e42213750e16cafdd0deae9accf61633e5e5 (diff)
Use forward iteration on selections, and take advantage of it when updating
SelectionList::update now is optimized for the common case where changes are sorted, the algorithm is O(m*n) with m the number of sorted ranges in the changes. In the common case, m should be very small.
Diffstat (limited to 'src/selection.hh')
-rw-r--r--src/selection.hh7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/selection.hh b/src/selection.hh
index 7e6fb2ad..651ee3fd 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -34,8 +34,11 @@ struct Selection
return m_anchor == other.m_anchor and m_cursor == other.m_cursor;
}
- const ByteCoord& min() const { return std::min(m_anchor, m_cursor); }
- const ByteCoord& max() const { return std::max(m_anchor, m_cursor); }
+ const ByteCoord& min() const { return m_anchor < m_cursor ? m_anchor : m_cursor; }
+ const ByteCoord& max() const { return m_anchor < m_cursor ? m_cursor : m_anchor; }
+
+ ByteCoord& min() { return m_anchor < m_cursor ? m_anchor : m_cursor; }
+ ByteCoord& max() { return m_anchor < m_cursor ? m_cursor : m_anchor; }
private:
ByteCoord m_anchor;