diff options
author | Jeffrey Stedfast <jeff@xamarin.com> | 2014-07-26 15:56:45 -0400 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2014-07-26 20:11:19 +0000 |
commit | 84aa4d1ff29004b0aa28068b7beb21f7ebfdb239 (patch) | |
tree | bd51fd73ed13ea3e455baf18d11c309a8eff4e06 | |
parent | b3d434a9701daab054981c891c645eefe1685b51 (diff) |
fdo#80908 - avoid lots of alloc/free of common integer values.
Change-Id: Ie170d44af062ec8c8b412b7de271e96a106971aa
Reviewed-on: https://gerrit.libreoffice.org/10559
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFactory.cxx | 4 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastContextHandler.cxx | 41 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFastHelper.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx | 32 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx | 7 |
5 files changed, 54 insertions, 32 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx index 7546096a588b..2e739300b538 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.cxx +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -166,7 +166,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, { sal_Int32 nValue; pAttribs->getAsInteger(nToken,nValue); - OOXMLValue::Pointer_t xValue(new OOXMLIntegerValue(nValue)); + OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue); pHandler->newProperty(nId, xValue); pFactory->attributeAction(pHandler, nToken, xValue); } @@ -198,7 +198,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, { OUString aValue(Attribs->getValue(nToken)); sal_uInt32 nValue = (*pListValueMap)[aValue]; - OOXMLValue::Pointer_t xValue(new OOXMLIntegerValue(nValue)); + OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue); pHandler->newProperty(nId, xValue); pFactory->attributeAction(pHandler, nToken, xValue); } diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index be6319fda578..4e85d6460962 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -452,15 +452,13 @@ void OOXMLFastContextHandler::sendTableDepth() const { OOXMLPropertySet * pProps = new OOXMLPropertySetImpl(); { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(mnTableDepth)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); } { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(1)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); @@ -540,7 +538,7 @@ void OOXMLFastContextHandler::endParagraphGroup() void OOXMLFastContextHandler::startSdt() { OOXMLPropertySet * pProps = new OOXMLPropertySetImpl(); - OOXMLValue::Pointer_t pVal(new OOXMLIntegerValue(1)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtContent, pVal, OOXMLPropertyImpl::ATTRIBUTE)); pProps->add(pProp); mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps)); @@ -549,7 +547,7 @@ void OOXMLFastContextHandler::startSdt() void OOXMLFastContextHandler::endSdt() { OOXMLPropertySet * pProps = new OOXMLPropertySetImpl(); - OOXMLValue::Pointer_t pVal(new OOXMLIntegerValue(1)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtEndContent, pVal, OOXMLPropertyImpl::ATTRIBUTE)); pProps->add(pProp); mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps)); @@ -1307,7 +1305,7 @@ void OOXMLFastContextHandlerValue::setDefaultIntegerValue() { if (mpValue.get() == NULL) { - OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(0)); + OOXMLValue::Pointer_t pValue = OOXMLIntegerValue::Create(0); setValue(pValue); } } @@ -1468,15 +1466,13 @@ void OOXMLFastContextHandlerTextTableCell::endCell() { OOXMLPropertySet * pProps = new OOXMLPropertySetImpl(); { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(mnTableDepth)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); } { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(1)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); @@ -1518,22 +1514,19 @@ void OOXMLFastContextHandlerTextTableRow::endRow() { OOXMLPropertySet * pProps = new OOXMLPropertySetImpl(); { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(mnTableDepth)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); } { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(1)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); } { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(1)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_tblRow, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); @@ -1567,15 +1560,13 @@ void OOXMLFastContextHandlerTextTableRow::handleGridBefore( OOXMLValue::Pointer_ // This whole part is OOXMLFastContextHandlerTextTableCell::endCell() . OOXMLPropertySet * pProps = new OOXMLPropertySetImpl(); { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(mnTableDepth)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); } { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(1)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); @@ -1613,7 +1604,7 @@ void OOXMLFastContextHandlerTextTableRow::handleGridBefore( OOXMLValue::Pointer_ OOXMLProperty::Pointer_t OOXMLFastContextHandlerTextTableRow::fakeNoBorder( Id id ) { OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySetImpl()); - OOXMLValue::Pointer_t pVal(new OOXMLIntegerValue(0)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(0); OOXMLProperty::Pointer_t pPropVal (new OOXMLPropertyImpl(NS_ooxml::LN_CT_Border_val, pVal, OOXMLPropertyImpl::ATTRIBUTE)); pProps->add(pPropVal); @@ -1648,8 +1639,7 @@ void OOXMLFastContextHandlerTextTable::lcl_startFastElement boost::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl ); { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(mnTableDepth)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_tblStart, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); @@ -1667,8 +1657,7 @@ void OOXMLFastContextHandlerTextTable::lcl_endFastElement boost::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl ); { - OOXMLValue::Pointer_t pVal - (new OOXMLIntegerValue(mnTableDepth)); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); OOXMLProperty::Pointer_t pProp (new OOXMLPropertyImpl(NS_ooxml::LN_tblEnd, pVal, OOXMLPropertyImpl::SPRM)); pProps->add(pProp); diff --git a/writerfilter/source/ooxml/OOXMLFastHelper.hxx b/writerfilter/source/ooxml/OOXMLFastHelper.hxx index b272683057e7..6958aa2260fe 100644 --- a/writerfilter/source/ooxml/OOXMLFastHelper.hxx +++ b/writerfilter/source/ooxml/OOXMLFastHelper.hxx @@ -78,7 +78,7 @@ void OOXMLFastHelper<T>::newProperty(OOXMLFastContextHandler * pHandler, Id nId, sal_Int32 nVal) { - OOXMLValue::Pointer_t pVal(new T(nVal)); + OOXMLValue::Pointer_t pVal(T::Create(nVal)); pHandler->newProperty(nId, pVal); } diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx index 258922571424..c399af0df421 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx @@ -583,6 +583,38 @@ OOXMLValue * OOXMLPropertySetValue::clone() const class OOXMLIntegerValue */ +OOXMLValue::Pointer_t OOXMLIntegerValue::Create(sal_Int32 nValue) +{ + static OOXMLValue::Pointer_t Zero(new OOXMLIntegerValue (0)); + static OOXMLValue::Pointer_t One(new OOXMLIntegerValue (1)); + static OOXMLValue::Pointer_t Two(new OOXMLIntegerValue (2)); + static OOXMLValue::Pointer_t Three(new OOXMLIntegerValue (3)); + static OOXMLValue::Pointer_t Four(new OOXMLIntegerValue (4)); + static OOXMLValue::Pointer_t Five(new OOXMLIntegerValue (5)); + static OOXMLValue::Pointer_t Six(new OOXMLIntegerValue (6)); + static OOXMLValue::Pointer_t Seven(new OOXMLIntegerValue (7)); + static OOXMLValue::Pointer_t Eight(new OOXMLIntegerValue (8)); + static OOXMLValue::Pointer_t Nine(new OOXMLIntegerValue (9)); + + switch (nValue) { + case 0: return Zero; + case 1: return One; + case 2: return Two; + case 3: return Three; + case 4: return Four; + case 5: return Five; + case 6: return Six; + case 7: return Seven; + case 8: return Eight; + case 9: return Nine; + default: break; + } + + OOXMLValue::Pointer_t value(new OOXMLIntegerValue(nValue)); + + return value; +} + OOXMLIntegerValue::OOXMLIntegerValue(sal_Int32 nValue) : mnValue(nValue) { diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx index bade78458b61..e820fdeec1ee 100644 --- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx +++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx @@ -103,12 +103,12 @@ class OOXMLBooleanValue : public OOXMLValue { protected: bool mbValue; + explicit OOXMLBooleanValue(bool bValue); + explicit OOXMLBooleanValue(const char *pValue); public: static OOXMLValue::Pointer_t Create (bool bValue); static OOXMLValue::Pointer_t Create (const char *pValue); - explicit OOXMLBooleanValue(bool bValue); - explicit OOXMLBooleanValue(const char *pValue); virtual ~OOXMLBooleanValue(); virtual int getInt() const SAL_OVERRIDE; @@ -205,8 +205,9 @@ class OOXMLIntegerValue : public OOXMLValue { protected: sal_Int32 mnValue; -public: explicit OOXMLIntegerValue(sal_Int32 nValue); +public: + static OOXMLValue::Pointer_t Create (sal_Int32 nValue); virtual ~OOXMLIntegerValue(); virtual int getInt() const SAL_OVERRIDE; |