summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-04 10:53:01 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-04 12:26:23 +0200
commite23436d347bb44a720932a2e7badc56147f5b167 (patch)
tree1cc0f8f00fe067e144e32fec6be79759815b8f76 /editeng
parent9fed7b07af44792012028eb57900640a5ee833cb (diff)
speed up loading large ODS a little
by flattening the XEditAttribute list, which reduces memory allocations Change-Id: Iae913a6aac3e438ea1e00f19556f6a75713cd4fb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115060 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/editobj.cxx56
-rw-r--r--editeng/source/editeng/editobj2.hxx15
-rw-r--r--editeng/source/editeng/fieldupdater.cxx4
-rw-r--r--editeng/source/editeng/impedit4.cxx20
4 files changed, 36 insertions, 59 deletions
diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx
index 2cb69858510b..2736021b85cd 100644
--- a/editeng/source/editeng/editobj.cxx
+++ b/editeng/source/editeng/editobj.cxx
@@ -46,13 +46,12 @@ using std::endl;
using namespace com::sun::star;
-static std::unique_ptr<XEditAttribute> MakeXEditAttribute( SfxItemPool& rPool, const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd )
+static XEditAttribute MakeXEditAttribute( SfxItemPool& rPool, const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd )
{
// Create the new attribute in the pool
const SfxPoolItem& rNew = rPool.Put( rItem );
- std::unique_ptr<XEditAttribute> pNew(new XEditAttribute( rNew, nStart, nEnd ));
- return pNew;
+ return XEditAttribute( rNew, nStart, nEnd );
}
XEditAttribute::XEditAttribute( const SfxPoolItem& rAttr, sal_Int32 nS, sal_Int32 nE )
@@ -62,11 +61,6 @@ XEditAttribute::XEditAttribute( const SfxPoolItem& rAttr, sal_Int32 nS, sal_Int3
{
}
-XEditAttribute::~XEditAttribute()
-{
- pItem = nullptr; // belongs to the Pool.
-}
-
bool XEditAttribute::IsFeature() const
{
sal_uInt16 nWhich = pItem->Which();
@@ -113,12 +107,11 @@ ContentInfo::ContentInfo( const ContentInfo& rCopyFrom, SfxItemPool& rPoolToUse
// this should ensure that the Items end up in the correct Pool!
aParaAttribs.Set( rCopyFrom.GetParaAttribs() );
- for (const auto & aAttrib : rCopyFrom.maCharAttribs)
+ for (const XEditAttribute & rAttr : rCopyFrom.maCharAttribs)
{
- const XEditAttribute& rAttr = *aAttrib;
- std::unique_ptr<XEditAttribute> pMyAttr = MakeXEditAttribute(
+ XEditAttribute aMyAttr = MakeXEditAttribute(
rPoolToUse, *rAttr.GetItem(), rAttr.GetStart(), rAttr.GetEnd());
- maCharAttribs.push_back(std::move(pMyAttr));
+ maCharAttribs.push_back(aMyAttr);
}
if ( rCopyFrom.GetWrongList() )
@@ -128,7 +121,7 @@ ContentInfo::ContentInfo( const ContentInfo& rCopyFrom, SfxItemPool& rPoolToUse
ContentInfo::~ContentInfo()
{
for (auto const& charAttrib : maCharAttribs)
- aParaAttribs.GetPool()->Remove(*charAttrib->GetItem());
+ aParaAttribs.GetPool()->Remove(*charAttrib.GetItem());
maCharAttribs.clear();
}
@@ -160,9 +153,9 @@ void ContentInfo::dumpAsXml(xmlTextWriterPtr pWriter) const
for (size_t i=0; i<maCharAttribs.size(); ++i)
{
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("attribs"));
- (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("start"), "%" SAL_PRIdINT32, maCharAttribs[i]->GetStart());
- (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("end"), "%" SAL_PRIdINT32, maCharAttribs[i]->GetEnd());
- maCharAttribs[i]->GetItem()->dumpAsXml(pWriter);
+ (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("start"), "%" SAL_PRIdINT32, maCharAttribs[i].GetStart());
+ (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("end"), "%" SAL_PRIdINT32, maCharAttribs[i].GetEnd());
+ maCharAttribs[i].GetItem()->dumpAsXml(pWriter);
(void)xmlTextWriterEndElement(pWriter);
}
(void)xmlTextWriterEndElement(pWriter);
@@ -210,12 +203,7 @@ bool ContentInfo::Equals(const ContentInfo& rCompare, bool bComparePool) const
{
return maText == rCompare.maText && aStyle == rCompare.aStyle && eFamily == rCompare.eFamily
&& aParaAttribs.Equals(rCompare.aParaAttribs, bComparePool)
- && std::equal(maCharAttribs.cbegin(), maCharAttribs.cend(),
- rCompare.maCharAttribs.cbegin(), rCompare.maCharAttribs.cend(),
- [](const std::unique_ptr<XEditAttribute>& pAttribute1,
- const std::unique_ptr<XEditAttribute>& pAttribute2) -> bool {
- return *pAttribute1 == *pAttribute2;
- });
+ && maCharAttribs == rCompare.maCharAttribs;
}
EditTextObject::EditTextObject( SfxItemPool* pPool ) :
@@ -654,14 +642,14 @@ void EditTextObjectImpl::SetScriptType( SvtScriptType nType )
nScriptType = nType;
}
-std::unique_ptr<XEditAttribute> EditTextObjectImpl::CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd )
+XEditAttribute EditTextObjectImpl::CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd )
{
return MakeXEditAttribute( *pPool, rItem, nStart, nEnd );
}
-void EditTextObjectImpl::DestroyAttrib( std::unique_ptr<XEditAttribute> pAttr )
+void EditTextObjectImpl::DestroyAttrib( const XEditAttribute& rAttr )
{
- pPool->Remove( *pAttr->GetItem() );
+ pPool->Remove( *rAttr.GetItem() );
}
@@ -712,9 +700,8 @@ void EditTextObjectImpl::GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttr
rLst.clear();
const ContentInfo& rC = *aContents[nPara];
- for (const auto & aAttrib : rC.maCharAttribs)
+ for (const XEditAttribute & rAttr : rC.maCharAttribs)
{
- const XEditAttribute& rAttr = *aAttrib;
EECharAttrib aEEAttr(rAttr.GetStart(), rAttr.GetEnd(), rAttr.GetItem());
rLst.push_back(aEEAttr);
}
@@ -735,7 +722,7 @@ const SvxFieldItem* EditTextObjectImpl::GetField() const
size_t nAttribs = rC.maCharAttribs.size();
for (size_t nAttr = nAttribs; nAttr; )
{
- const XEditAttribute& rX = *rC.maCharAttribs[--nAttr];
+ const XEditAttribute& rX = rC.maCharAttribs[--nAttr];
if (rX.GetItem()->Which() == EE_FEATURE_FIELD)
return static_cast<const SvxFieldItem*>(rX.GetItem());
}
@@ -755,9 +742,8 @@ const SvxFieldData* EditTextObjectImpl::GetFieldData(sal_Int32 nPara, size_t nPo
return nullptr;
size_t nCurPos = 0;
- for (auto const& charAttrib : rC.maCharAttribs)
+ for (XEditAttribute const& rAttr : rC.maCharAttribs)
{
- const XEditAttribute& rAttr = *charAttrib;
if (rAttr.GetItem()->Which() != EE_FEATURE_FIELD)
// Skip attributes that are not fields.
continue;
@@ -787,7 +773,7 @@ bool EditTextObjectImpl::HasField( sal_Int32 nType ) const
size_t nAttrs = rC.maCharAttribs.size();
for (size_t nAttr = 0; nAttr < nAttrs; ++nAttr)
{
- const XEditAttribute& rAttr = *rC.maCharAttribs[nAttr];
+ const XEditAttribute& rAttr = rC.maCharAttribs[nAttr];
if (rAttr.GetItem()->Which() != EE_FEATURE_FIELD)
continue;
@@ -819,7 +805,7 @@ bool EditTextObjectImpl::RemoveCharAttribs( sal_uInt16 _nWhich )
for (size_t nAttr = rC.maCharAttribs.size(); nAttr; )
{
- XEditAttribute& rAttr = *rC.maCharAttribs[--nAttr];
+ XEditAttribute& rAttr = rC.maCharAttribs[--nAttr];
if ( !_nWhich || (rAttr.GetItem()->Which() == _nWhich) )
{
pPool->Remove(*rAttr.GetItem());
@@ -873,9 +859,8 @@ void EditTextObjectImpl::GetAllSections( std::vector<editeng::Section>& rAttrs )
std::vector<size_t>& rBorders = aParaBorders[nPara];
rBorders.push_back(0);
rBorders.push_back(rC.GetText().getLength());
- for (const auto & aAttrib : rC.maCharAttribs)
+ for (const XEditAttribute & rAttr : rC.maCharAttribs)
{
- const XEditAttribute& rAttr = *aAttrib;
const SfxPoolItem* pItem = rAttr.GetItem();
if (!pItem)
continue;
@@ -937,9 +922,8 @@ void EditTextObjectImpl::GetAllSections( std::vector<editeng::Section>& rAttrs )
return;
}
- for (const auto & aAttrib : rC.maCharAttribs)
+ for (const XEditAttribute & rXAttr : rC.maCharAttribs)
{
- const XEditAttribute& rXAttr = *aAttrib;
const SfxPoolItem* pItem = rXAttr.GetItem();
if (!pItem)
continue;
diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx
index 45862f31303d..ba9603a7416d 100644
--- a/editeng/source/editeng/editobj2.hxx
+++ b/editeng/source/editeng/editobj2.hxx
@@ -49,11 +49,8 @@ private:
sal_Int32 nStart;
sal_Int32 nEnd;
- XEditAttribute( const XEditAttribute& rCopyFrom ) = delete;
-
public:
XEditAttribute( const SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
- ~XEditAttribute();
const SfxPoolItem* GetItem() const { return pItem; }
@@ -116,14 +113,12 @@ public:
class ContentInfo
{
friend class EditTextObjectImpl;
-public:
- typedef std::vector<std::unique_ptr<XEditAttribute> > XEditAttributesType;
private:
svl::SharedString maText;
OUString aStyle;
- XEditAttributesType maCharAttribs;
+ std::vector<XEditAttribute> maCharAttribs;
SfxStyleFamily eFamily;
SfxItemSet aParaAttribs;
std::unique_ptr<WrongList>
@@ -144,8 +139,8 @@ public:
void dumpAsXml(xmlTextWriterPtr pWriter) const;
- const XEditAttributesType& GetCharAttribs() const { return maCharAttribs; }
- XEditAttributesType& GetCharAttribs() { return maCharAttribs; }
+ const std::vector<XEditAttribute>& GetCharAttribs() const { return maCharAttribs; }
+ std::vector<XEditAttribute>& GetCharAttribs() { return maCharAttribs; }
const OUString& GetStyle() const { return aStyle; }
SfxStyleFamily GetFamily() const { return eFamily; }
@@ -217,8 +212,8 @@ public:
void SetScriptType( SvtScriptType nType );
ContentInfo* CreateAndInsertContent();
- std::unique_ptr<XEditAttribute> CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd );
- void DestroyAttrib( std::unique_ptr<XEditAttribute> pAttr );
+ XEditAttribute CreateAttrib( const SfxPoolItem& rItem, sal_Int32 nStart, sal_Int32 nEnd );
+ void DestroyAttrib( const XEditAttribute& rAttr );
ContentInfosType& GetContents() { return aContents;}
const ContentInfosType& GetContents() const { return aContents;}
diff --git a/editeng/source/editeng/fieldupdater.cxx b/editeng/source/editeng/fieldupdater.cxx
index ec9266926bd6..b342aacca48b 100644
--- a/editeng/source/editeng/fieldupdater.cxx
+++ b/editeng/source/editeng/fieldupdater.cxx
@@ -31,10 +31,8 @@ public:
for (std::unique_ptr<ContentInfo> & i : rContents)
{
ContentInfo& rContent = *i;
- ContentInfo::XEditAttributesType& rAttribs = rContent.GetCharAttribs();
- for (std::unique_ptr<XEditAttribute> & rAttrib : rAttribs)
+ for (XEditAttribute & rAttr : rContent.GetCharAttribs())
{
- XEditAttribute& rAttr = *rAttrib;
const SfxPoolItem* pItem = rAttr.GetItem();
if (pItem->Which() != EE_FEATURE_FIELD)
// This is not a field item.
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index fc4348764796..2f523613dd4c 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -1062,24 +1062,24 @@ std::unique_ptr<EditTextObject> ImpEditEngine::CreateTextObject( EditSelection a
if ( bEmptyPara ||
( ( pAttr->GetEnd() > nStartPos ) && ( pAttr->GetStart() < nEndPos ) ) )
{
- std::unique_ptr<XEditAttribute> pX = pTxtObj->mpImpl->CreateAttrib(*pAttr->GetItem(), pAttr->GetStart(), pAttr->GetEnd());
+ XEditAttribute aX = pTxtObj->mpImpl->CreateAttrib(*pAttr->GetItem(), pAttr->GetStart(), pAttr->GetEnd());
// Possibly Correct ...
if ( ( nNode == nStartNode ) && ( nStartPos != 0 ) )
{
- pX->GetStart() = ( pX->GetStart() > nStartPos ) ? pX->GetStart()-nStartPos : 0;
- pX->GetEnd() = pX->GetEnd() - nStartPos;
+ aX.GetStart() = ( aX.GetStart() > nStartPos ) ? aX.GetStart()-nStartPos : 0;
+ aX.GetEnd() = aX.GetEnd() - nStartPos;
}
if ( nNode == nEndNode )
{
- if ( pX->GetEnd() > (nEndPos-nStartPos) )
- pX->GetEnd() = nEndPos-nStartPos;
+ if ( aX.GetEnd() > (nEndPos-nStartPos) )
+ aX.GetEnd() = nEndPos-nStartPos;
}
- DBG_ASSERT( pX->GetEnd() <= (nEndPos-nStartPos), "CreateBinTextObject: Attribute too long!" );
- if ( !pX->GetLen() && !bEmptyPara )
- pTxtObj->mpImpl->DestroyAttrib(std::move(pX));
+ DBG_ASSERT( aX.GetEnd() <= (nEndPos-nStartPos), "CreateBinTextObject: Attribute too long!" );
+ if ( !aX.GetLen() && !bEmptyPara )
+ pTxtObj->mpImpl->DestroyAttrib(aX);
else
- rCAttriblist.push_back(std::move(pX));
+ rCAttriblist.push_back(std::move(aX));
}
nAttr++;
pAttr = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
@@ -1225,7 +1225,7 @@ EditSelection ImpEditEngine::InsertTextObject( const EditTextObject& rTextObject
bool bUpdateFields = false;
for (size_t nAttr = 0; nAttr < nNewAttribs; ++nAttr)
{
- const XEditAttribute& rX = *pC->GetCharAttribs()[nAttr];
+ const XEditAttribute& rX = pC->GetCharAttribs()[nAttr];
// Can happen when paragraphs > 16K, it is simply wrapped.
//TODO! Still true, still needed?
if ( rX.GetEnd() <= aPaM.GetNode()->Len() )