From 9c89caa036feb0977922f3452e324b97d13bb735 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Thu, 28 Dec 2017 19:01:14 +0100 Subject: Optimize a bit RowSetCache (dbacess) Change-Id: I051cb40b5dd854a4a104eae7124564cab8a35de1 Reviewed-on: https://gerrit.libreoffice.org/47151 Reviewed-by: Lionel Elie Mamane Tested-by: Jenkins --- dbaccess/source/core/api/RowSetCache.cxx | 49 +++++++++++++++++++------------- 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx index d635e12a7331..923a41cc8356 100644 --- a/dbaccess/source/core/api/RowSetCache.cxx +++ b/dbaccess/source/core/api/RowSetCache.cxx @@ -913,28 +913,31 @@ void ORowSetCache::moveWindow() } std::rotate(m_pMatrix->begin(), aEnd, aNewEnd); - // now correct the iterator in our iterator vector - // rotateCacheIterator(aEnd-m_pMatrix->begin()); //can't be used because they decrement and here we need to increment - ORowSetCacheMap::iterator aCacheIter = m_aCacheIterators.begin(); - const ORowSetCacheMap::const_iterator aCacheEnd = m_aCacheIterators.end(); - for(;aCacheIter != aCacheEnd;++aCacheIter) + if (!m_bModified) { - if ( !aCacheIter->second.pRowSet->isInsertRow() - && aCacheIter->second.aIterator != m_pMatrix->end() && !m_bModified ) + // now correct the iterator in our iterator vector + // rotateCacheIterator(aEnd-m_pMatrix->begin()); //can't be used because they decrement and here we need to increment + ORowSetCacheMap::iterator aCacheIter = m_aCacheIterators.begin(); + const ORowSetCacheMap::const_iterator aCacheEnd = m_aCacheIterators.end(); + for(;aCacheIter != aCacheEnd;++aCacheIter) { - const ptrdiff_t nDist = (aCacheIter->second.aIterator - m_pMatrix->begin()); - if ( nDist >= nOverlapSize ) - { - // That's from outside the overlap area; invalidate iterator. - aCacheIter->second.aIterator = m_pMatrix->end(); - } - else + if ( !aCacheIter->second.pRowSet->isInsertRow() + && aCacheIter->second.aIterator != m_pMatrix->end() ) { - // Inside overlap area: move to correct position - CHECK_MATRIX_POS( (nDist + nStartPosOffset) ); - aCacheIter->second.aIterator += nStartPosOffset; - OSL_ENSURE(aCacheIter->second.aIterator >= m_pMatrix->begin() + const ptrdiff_t nDist = (aCacheIter->second.aIterator - m_pMatrix->begin()); + if ( nDist >= nOverlapSize ) + { + // That's from outside the overlap area; invalidate iterator. + aCacheIter->second.aIterator = m_pMatrix->end(); + } + else + { + // Inside overlap area: move to correct position + CHECK_MATRIX_POS( (nDist + nStartPosOffset) ); + aCacheIter->second.aIterator += nStartPosOffset; + OSL_ENSURE(aCacheIter->second.aIterator >= m_pMatrix->begin() && aCacheIter->second.aIterator < m_pMatrix->end(),"Iterator out of area!"); + } } } } @@ -1448,6 +1451,9 @@ void ORowSetCache::deleteIterator(const ORowSetBase* _pRowSet) void ORowSetCache::rotateCacheIterator(ORowSetMatrix::difference_type _nDist) { + if (m_bModified) + return; + if(_nDist) { // now correct the iterator in our iterator vector @@ -1456,7 +1462,7 @@ void ORowSetCache::rotateCacheIterator(ORowSetMatrix::difference_type _nDist) for(;aCacheIter != aCacheEnd;++aCacheIter) { if ( !aCacheIter->second.pRowSet->isInsertRow() - && aCacheIter->second.aIterator != m_pMatrix->end() && !m_bModified ) + && aCacheIter->second.aIterator != m_pMatrix->end()) { ptrdiff_t nDist = (aCacheIter->second.aIterator - m_pMatrix->begin()); if(nDist < _nDist) @@ -1477,11 +1483,14 @@ void ORowSetCache::rotateCacheIterator(ORowSetMatrix::difference_type _nDist) void ORowSetCache::rotateAllCacheIterators() { + if (m_bModified) + return; + // now correct the iterator in our iterator vector auto aCacheEnd = m_aCacheIterators.end(); for (auto aCacheIter = m_aCacheIterators.begin(); aCacheIter != aCacheEnd; ++aCacheIter) { - if (!aCacheIter->second.pRowSet->isInsertRow() && !m_bModified) + if (!aCacheIter->second.pRowSet->isInsertRow()) { aCacheIter->second.aIterator = m_pMatrix->end(); } -- cgit