[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/sdk/kdevelop/languages/cpp/parser/rpp
From: Milian Wolff <mail () milianw ! de>
Date: 2010-03-29 12:31:18
Message-ID: 20100329123118.DBB1AAC883 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1108611 by mwolff:
Introduce cache for positionAt, relative to last accessed anchor.
Works well since the LocationTable only appends stuff, never
invalidates the items already there.
Speed up is most noticable for files with long lines, like
generated templates in boost. Speedup for vector200.hpp is
around 30%:
Before:
real 2m2.048s
user 2m0.920s
sys 0m0.450s
After:
real 1m28.327s
user 1m26.970s
sys 0m0.660s
M +23 -1 pp-location.cpp
M +5 -0 pp-location.h
--- trunk/extragear/sdk/kdevelop/languages/cpp/parser/rpp/pp-location.cpp \
#1108610:1108611 @@ -27,6 +27,11 @@
using namespace rpp;
+bool LocationTable::AnchorInTable::operator==(const LocationTable::AnchorInTable& \
other) const +{
+ return other.nextPosition == nextPosition && other.position == position && \
other.anchor == anchor && other.nextAnchor == nextAnchor; +}
+
LocationTable::LocationTable()
{
anchor(0, Anchor(0,0), 0);
@@ -48,10 +53,27 @@
{
AnchorInTable ret = anchorForOffset(offset, collapseIfMacroExpansion);
- if(!ret.anchor.collapsed)
+ if (m_lastAnchorInTable == ret && offset >= m_positionAtLastOffset) {
+ // use cached position
+ ret.anchor.column = m_positionAtColumnCache;
+
+ for(std::size_t a = m_positionAtLastOffset; a < offset; ++a)
+ ret.anchor.column += KDevelop::IndexedString::lengthFromIndex(contents[a]);
+
+ m_positionAtColumnCache = ret.anchor.column;
+ m_positionAtLastOffset = offset;
+ } else if(!ret.anchor.collapsed) {
+ // save anchor _before_ changing it's members
+ m_lastAnchorInTable = ret;
+
for(std::size_t a = ret.position; a < offset; ++a)
ret.anchor.column += KDevelop::IndexedString::lengthFromIndex(contents[a]);
+ m_positionAtColumnCache = ret.anchor.column;
+ m_positionAtLastOffset = offset;
+ }
+
+
uint room = 0;
if(ret.nextPosition)
if(ret.nextAnchor.line == ret.anchor.line && ret.nextAnchor.column > \
ret.anchor.column)
--- trunk/extragear/sdk/kdevelop/languages/cpp/parser/rpp/pp-location.h \
#1108610:1108611 @@ -58,6 +58,7 @@
Anchor anchor; //This anchor
uint nextPosition;//Position of the next following anchor, or zero
Anchor nextAnchor;//The next following anchor
+ bool operator==(const AnchorInTable& other) const;
};
/**
@@ -81,6 +82,10 @@
typedef QMap<std::size_t, Anchor> OffsetTable;
OffsetTable m_offsetTable;
mutable OffsetTable::ConstIterator m_currentOffset;
+ //cache for positionAt
+ mutable AnchorInTable m_lastAnchorInTable;
+ mutable int m_positionAtColumnCache;
+ mutable std::size_t m_positionAtLastOffset;
};
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic