[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kate/buffer
From: David Nolden <david.nolden.kde () art-master ! de>
Date: 2010-07-15 21:44:25
Message-ID: 20100715214425.37A74AC73D () svn ! kde ! org
[Download RAW message or body]
SVN commit 1150413 by zwabel:
Make KatetextTextBuffer::rangesForLine much faster, by making all required \
information available through non-virtual functions and using those. Use binary \
search in KateTextBuffer::blockForLine.
M +3 -2 katetextblock.h
M +12 -5 katetextbuffer.cpp
M +22 -0 katetextcursor.h
M +18 -0 katetextrange.h
--- trunk/KDE/kdelibs/kate/buffer/katetextblock.h #1150412:1150413
@@ -25,13 +25,14 @@
#include <QtCore/QSet>
#include "katepartprivate_export.h"
-#include "katetextrange.h"
-#include "katetextcursor.h"
+#include <ktexteditor/cursor.h>
#include "katetextline.h"
namespace Kate {
class TextBuffer;
+class TextCursor;
+class TextRange;
/**
* Class representing a text block.
--- trunk/KDE/kdelibs/kate/buffer/katetextbuffer.cpp #1150412:1150413
@@ -355,6 +355,8 @@
// block to start search with
int index = m_lastUsedBlock;
+ int blockStart = 0;
+ int blockEnd = m_blocks.size();
// check if start is ok
if (index < 0 || index >= m_blocks.size())
@@ -373,10 +375,15 @@
}
if (line < start)
- index--;
- else
- index++;
+ {
+ // Search left of index
+ blockEnd = index;
+ }else{
+ // Search right of index
+ blockStart = index+1;
}
+ index = (blockStart + (blockEnd-1)) / 2;
+ }
// we should always find a block
Q_ASSERT (false);
@@ -733,7 +740,7 @@
/**
* we want only ranges with attributes, but this one has none
*/
- if (rangesWithAttributeOnly && !range->attribute())
+ if (rangesWithAttributeOnly && !range->hasAttribute())
continue;
/**
@@ -751,7 +758,7 @@
/**
* if line is in the range, ok
*/
- if (range->start().line() <= line && line <= range->end().line())
+ if (range->startInternal().lineInternal() <= line && line <= \
range->endInternal().lineInternal()) rightRanges.append (range);
}
--- trunk/KDE/kdelibs/kate/buffer/katetextcursor.h #1150412:1150413
@@ -27,6 +27,7 @@
#include <ktexteditor/movingcursor.h>
#include "katepartprivate_export.h"
+#include "katetextblock.h"
namespace Kate {
@@ -112,12 +113,33 @@
int line() const;
/**
+ * Non-virtual version of line(), which is faster.
+ * Inlined for fast access (especially in KateTextBuffer::rangesForLine
+ * \return line number, where 0 is the first line.
+ */
+ int lineInternal() const
+ {
+ // invalid cursor have no block
+ if (!m_block)
+ return -1;
+
+ // else, calculate real line
+ return m_block->startLine () + m_line;
+ }
+
+ /**
* Retrieve the column on which this cursor is situated.
* \return column number, where 0 is the first column.
*/
int column() const { return m_column; }
/**
+ * Non-virtual version of column(), which is faster.
+ * \return column number, where 0 is the first column.
+ * */
+ int columnInternal() const { return m_column; }
+
+ /**
* Get range this cursor belongs to, if any
* @return range this pointer is part of, else 0
*/
--- trunk/KDE/kdelibs/kate/buffer/katetextrange.h #1150412:1150413
@@ -119,12 +119,24 @@
const KTextEditor::MovingCursor &start () const { return m_start; }
/**
+ * Non-virtual version of start(), which is faster.
+ * @return start cursor
+ */
+ const TextCursor &startInternal() const { return m_start; }
+
+ /**
* Retrieve end cursor of this range, read-only.
* @return end cursor
*/
const KTextEditor::MovingCursor &end () const { return m_end; }
/**
+ * Nonvirtual version of end(), which is faster.
+ * @return end cursor
+ */
+ const TextCursor &endInternal () const { return m_end; }
+
+ /**
* Convert this clever range into a dumb one.
* @return normal range
*/
@@ -161,6 +173,12 @@
KTextEditor::Attribute::Ptr attribute () const { return m_attribute; }
/**
+ * \return whether a nonzero attribute is set. This is faster than checking \
attribute(), + * because the reference-counting is omitted.
+ */
+ bool hasAttribute() const { return !m_attribute.isNull(); }
+
+ /**
* Sets the currently active attribute for this range.
* This will trigger update of the relevant view parts.
*
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic