summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/inc/densebplustree.cxx13
-rw-r--r--sw/inc/densebplustree.hxx3
2 files changed, 14 insertions, 2 deletions
diff --git a/sw/inc/densebplustree.cxx b/sw/inc/densebplustree.cxx
index 62c2394a145c..c936ad8a0ee2 100644
--- a/sw/inc/densebplustree.cxx
+++ b/sw/inc/densebplustree.cxx
@@ -146,6 +146,7 @@ struct DBPTreeNode
template < class Key, class Value >
DenseBPlusTree< Key, Value >::DenseBPlusTree()
: m_pRoot( new DBPTreeNode< Key, Value > ),
+ m_pLastLeaf( m_pRoot ),
m_nCount( 0 ),
m_nDepth( 1 )
{
@@ -161,8 +162,12 @@ template < class Key, class Value >
void DenseBPlusTree< Key, Value >::Insert( const Value& rValue, Key nPos )
{
NodeWithIndex pParents[ m_nDepth ];
- int nParentsLength;
- NodeWithIndex aLeaf = findLeaf( nPos, pParents, nParentsLength );
+ int nParentsLength = 0;
+ NodeWithIndex aLeaf( m_pLastLeaf, m_pLastLeaf->m_nUsed );
+
+ // if we are lucky, we just append, otherwise do the full job
+ if ( nPos != m_nCount || m_pLastLeaf->m_nUsed == sOrder )
+ aLeaf = findLeaf( nPos, pParents, nParentsLength );
if ( aLeaf.pNode->m_nUsed < sOrder )
{
@@ -316,6 +321,10 @@ DBPTreeNode< Key, Value >* DenseBPlusTree< Key, Value >::splitNode( DBPTreeNode<
DBPTreeNode< Key, Value > *pNewNode = new DBPTreeNode< Key, Value >;
int offset = pNewNode->copyFromSplitNode( pNode );
+ // update the last leaf if necessary
+ if ( pNode == m_pLastLeaf )
+ m_pLastLeaf = pNewNode;
+
if ( nParentsLength == 0 )
{
// we have to create a new root
diff --git a/sw/inc/densebplustree.hxx b/sw/inc/densebplustree.hxx
index 26d1dfbd0ccf..027e2d857674 100644
--- a/sw/inc/densebplustree.hxx
+++ b/sw/inc/densebplustree.hxx
@@ -103,6 +103,9 @@ private:
/// Root of the tree.
DBPTreeNode< Key, Value > *m_pRoot;
+ /// The last leaf node - only a small optimization for appends.
+ DBPTreeNode< Key, Value > *m_pLastLeaf;
+
/// Amount of values that we contain.
Key m_nCount;