Changeset View
Changeset View
Standalone View
Standalone View
src/utils/documentcursor.cpp
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | |||||
112 | 112 | | |||
113 | bool DocumentCursor::atStartOfDocument() const | 113 | bool DocumentCursor::atStartOfDocument() const | ||
114 | { | 114 | { | ||
115 | return line() == 0 && column() == 0; | 115 | return line() == 0 && column() == 0; | ||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | bool DocumentCursor::atEndOfDocument() const | 118 | bool DocumentCursor::atEndOfDocument() const | ||
119 | { | 119 | { | ||
120 | return m_cursor == document()->documentEnd(); | 120 | // avoid costly lineLength computation if we are not in the last line | ||
121 | // this is called often e.g. during search & replace, >> 2% of the total costs | ||||
122 | const auto lastLine = document()->lines() - 1; | ||||
123 | return line() == lastLine && column() == document()->lineLength(lastLine); | ||||
121 | } | 124 | } | ||
122 | 125 | | |||
123 | bool DocumentCursor::gotoNextLine() | 126 | bool DocumentCursor::gotoNextLine() | ||
124 | { | 127 | { | ||
125 | // only allow valid cursors | 128 | // only allow valid cursors | ||
126 | const bool ok = isValid() && (line() + 1 < document()->lines()); | 129 | const bool ok = isValid() && (line() + 1 < document()->lines()); | ||
127 | 130 | | |||
128 | if (ok) { | 131 | if (ok) { | ||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |